* Begin by preparing/formatting all datafiles:
	* Calcbench data for PPE
	* Calcbench data for pensions
	* Calcbench data for tax credits (amount)
	* Calcbench data for tax credits (percentage)
	* Calcbench data for pretax foreign earnings (mostly for banks/financial)
	
* Prep calcbench data (DTL for PPE):
clear
capture use "DIRECTORY\calcbench_ppe"

	* Standardize naming conventions so that they can be matched to Compustat
	rename cik_code cik 
	rename ticker tic 
	rename fiscal_year fyear 

keep cik tic fyear value 
duplicates drop cik tic fyear value, force 
* Delete observations where we have different values for the same variable
	duplicates tag cik tic fyear,gen(X)
	drop if X > 0 
	* Delete negative values	
	drop if value < 0 
save temp_ppe, replace 

* Prep calcbench data (DB Plans):
clear
capture import delim "DIRECTORY\calcbench_data_pension.csv"
	* Standardize naming conventions so that they can be matched to Compustat
	rename ticker tic 
	rename value dta_benefit 
	* Put amounts in millions USD
	replace dta_benefit = dta_benefit/1000000
	* Get fiscal year from date
	gen fyear = substr(fiscal_period,1,4)
	destring fyear,replace
	
keep cik tic fyear dta_benefit 
duplicates drop cik tic fyear dta_benefit, force 

* Delete observations where we have different values for the same variable
	duplicates tag cik tic fyear,gen(X)
	drop if X > 0 
	
rename dta_benefit benefits_dta
save temp_benefits, replace 

* Prep calcbench data (tax credits on the ETR statement):
clear
capture use "DIRECTORY\Data\etr_credits"
* Standardize naming so that it can be matched to Compustat
	rename cik_code cik 
	rename ticker tic 
	rename fiscal_year fyear 

keep cik tic fyear value 
rename value etrcredits
duplicates drop cik tic fyear etrcredits, force 

* Delete observations where we have different values for the same variable
	duplicates tag cik tic fyear,gen(X)
	drop if X > 0 
	
save temp_taxcredits, replace 

* Prep calcbench data (tax credit percentage on the ETR statement):
clear
capture use "DIRECTORY\etr_credit_pct"
* Standardize naming so that it can be matched to Compustat
	rename cik_code cik 
	rename ticker tic 
	rename fiscal_year fyear 

keep cik tic fyear value 
rename value credit_pct
duplicates drop cik tic fyear credit_pct, force 

* Delete observations where we have different values for the same variable
	duplicates tag cik tic fyear,gen(X)
	drop if X > 0 

save temp_taxcredit_pct, replace 

* Prep calcbench data - pretax foreign income:
clear 
capture use "DIRECTORY\pifo"
keep if metric == "EBITForeign"
* Standardize naming so that it can be matched to Compustat
	rename cik_code cik 
	rename ticker tic 
	rename fiscal_year fyear 
keep cik tic fyear value 
rename value pifo_1 
duplicates drop cik tic fyear pifo_1, force

* Delete observations where we have different values for the same variable
	duplicates tag cik tic fyear,gen(X) 
	drop if X > 0 
	drop X 
	
destring cik, replace 
save temp_pifo, replace 

* Modify Compustat data:
clear 
capture use "DIRECTORY\compustat_data_2009-2023.dta"
cd "DIRECTORY"

* Drop if missing key variables: 
	drop if missing(pi)
	drop if missing(txpd)
	duplicates tag gvkey fyear,gen(x0)
	drop if x0 > 0 & indfmt == "FS"

	* Merge with Calcbench Data:
		duplicates tag cik tic fyear ,gen(X)
		drop if X > 0 
		drop X
		merge 1:1 cik tic fyear using temp_ppe  
		drop if _merge == 2
		drop _merge 
		merge 1:1 cik tic fyear using temp_taxcredits
		drop if _merge == 2
		drop _merge 
		merge 1:1 cik tic fyear using temp_taxcredit_pct
		drop if _merge == 2
		drop _merge 
		destring cik, replace
		merge 1:1 cik tic fyear using temp_benefits
		drop if _merge == 2
		drop _merge 
		merge 1:1 cik tic fyear using temp_pifo 
		drop if _merge == 2 
		drop _merge 
		replace pifo_1 = pifo_1/1000000
		replace pifo = pifo_1 if missing(pifo)
		
		* For Calcbench data not already in millions USD, we convert here (DB amounts done in prior step):
		gen dtl = value/1000000
		replace etrcredits = etrcredits/1000000
		
* Adjust fiscal year for tax year:
	gen acct_end  = 0
	gen month = month(datadate)
	gen year = year(datadate)
	gen day = day(datadate)
	gen double acct_end_datadate = year * 10000+ month * 100 + day

	gen tax_year = .
	replace tax_year = 2008 if acct_end_datadate >= 20080701 & acct_end_datadate <= 20090630 
	replace tax_year = 2009 if acct_end_datadate >= 20090701 & acct_end_datadate <= 20100630 
	replace tax_year = 2010 if acct_end_datadate >= 20100701 & acct_end_datadate <= 20110630 
	replace tax_year = 2011 if acct_end_datadate >= 20110701 & acct_end_datadate <= 20120630 
	replace tax_year = 2012 if acct_end_datadate >= 20120701 & acct_end_datadate <= 20130630 
	replace tax_year = 2013 if acct_end_datadate >= 20130701 & acct_end_datadate <= 20140630 
	replace tax_year = 2014 if acct_end_datadate >= 20140701 & acct_end_datadate <= 20150630 
	replace tax_year = 2015 if acct_end_datadate >= 20150701 & acct_end_datadate <= 20160630 
	replace tax_year = 2016 if acct_end_datadate >= 20160701 & acct_end_datadate <= 20170630 
	replace tax_year = 2017 if acct_end_datadate >= 20170701 & acct_end_datadate <= 20180630 
	replace tax_year = 2018 if acct_end_datadate >= 20180701 & acct_end_datadate <= 20190630 
	replace tax_year = 2019 if acct_end_datadate >= 20190701 & acct_end_datadate <= 20200630
	replace tax_year = 2020 if acct_end_datadate >= 20200701 & acct_end_datadate <= 20210630 
	replace tax_year = 2021 if acct_end_datadate >= 20210701 & acct_end_datadate <= 20220630 
	replace tax_year = 2022 if acct_end_datadate >= 20220701 & acct_end_datadate <= 20230630 
	replace tax_year = 2023 if acct_end_datadate >= 20230701 & acct_end_datadate <= 20240630  
	drop year
	gen oldfyear = fyear
	replace fyear = tax_year
		egen gvkeyid = group(gvkey)
		duplicates tag gvkey fyear,gen(Xx)
		drop if Xx > 0 
		drop Xx
		xtset gvkeyid fyear 
	drop if fyear < 2010
* Drop if ticker contains a number (evidence of being a subsidiary)
	gen drop = 0 
	forvalues i = 1/9 {
		replace drop = 1 if strpos(tic,"`i'") > 0
	}
	drop if drop == 1 
	
/*
Try to estimate federal taxes paid by back SALT and foreign taxes out of cash tax paid
*/
	
	gen cash_etr = txpd/pi 
	gen etr = txt/pi 
	gen fed_tax = txpd - txs - txfo  
		replace fed_tax = txpd - txfo if missing(txs) & missing(fed_tax)
		replace fed_tax = txpd - txfo if missing(txs) & missing(fed_tax)
		replace fed_tax = txpd - txs if missing(fed_tax)
		replace fed_tax = txpd if missing(txs) & missing(fed_tax)
		replace fed_tax = txpd if missing(fed_tax)
		replace fed_tax = txfed + txdfed if missing(txpd) & missing(fed_tax)
		replace fed_tax = 0 if fed_tax < 0 
				
	* Try to find federal deferred taxes:	
	replace txdfed = txdi - txdfo - txds if txdfo != . & txds != . & txdfed == . & txt == txc + txdi		
	replace txdfed = txdi - txdfo if txdfo != . & txdfed == . & txt == txc + txdi
	* Try to find federal current taxes:	
	replace txfed = txc - txfo - txs if txfo != . & txs != . & txfed == . & txt == txc + txdi		

	drop if missing(fed_tax)	

* Create Table 1:
	* Save the file as a temp file so that we can construct table 1, which pulls out 
	* firms that would not be subject to CAMT and non-US firms
 
	save temp, replace
	
* Keep only if PI exceeds $1B USD:	
	keep if pi > 1000 & pi != .
	keep if fyear == 2021 | fyear == 2022 | fyear == 2020
	drop if loc != "USA"
	drop if fic != "USA"
* Drop non-C corps:
	capture drop X 
	drop if sic == "6798"
	gen X = 1 if strpos(conm,"TRUST")>0
		replace X = 1 if strpos(conm,"LLC")>0
		
	* Drop if 6-digit cusip ends in Y or Z
	gen cusip_6 = substr(cusip, 1,6)
	gen cusip_drop = substr(cusip_6,-1,.)
		replace X = 1 if cusip_drop == "Y" 
		replace X = 1 if cusip_drop == "Z" 
			
	* Drop if last two letters of conm strpos(conm, "LP")> 0
	gen var = substr(conm, -3,.)
		replace X = 1 if strpos(conm, "LLP")> 0 
		replace X = 1 if var == " LP" 	
	
	drop if X ==1
	
	label var at "Total Assets"
	label var lt "Total Liabilities"
	label var ni "Net Income"
	label var sale "Sales"
	label var pi "Pretax Income"
	label var pidom "Pretax Domestic Income"
	label var pifo "Pretax Foreign Income"
	label var txfed "Federal Income Tax"
	label var txdfed "Deferred Federal Income Tax"
	label var txfo "Foreign Income Tax"
	label var txdfo "Foreign Deferred Income Tax"
	label var txpd "Cash Taxes Paid"
	label var txs "State and Local Income Taxes"

* This creates Panel A of Table 1:
estpost sum at lt ni sale pi pidom pifo txfed txdfed txfo txdfo txpd txs etr cash_etr , detail 
	esttab, cells("count p5 p25 p50 p75 p95 mean sd") noobs sfmt(%12.2fc) 
	eststo clear 

* Return to the saved file and calculate AFSI for firms so that we can create 
* Table 1 panel B, which is restricted to firms that are applicable corporations:
	use temp ,clear

forvalues i = 2010/2022 {
	gen afsi_`i'_0 = pi if pi > 1000 & fyear == `i' 
	gen tax_paid_`i'_0 = fed_tax if fyear == `i' 
	replace tax_paid_`i'_0 = 0 if tax_paid_`i'_0 < 0
	gen tent_camt_`i'_0 = afsi_`i'_0 * .15 
	
	gen xcamt_liab_`i'_0 = tent_camt_`i'_0 - tax_paid_`i'_0
		replace xcamt_liab_`i'_0 = 0 if xcamt_liab_`i'_0 < 0
		replace xcamt_liab_`i'_0 = 0 if fyear != `i'
		replace xcamt_liab_`i'_0 = 0 if missing(xcamt_liab_`i'_0)	
	egen camt_liab_`i'_0 = sum(xcamt_liab_`i'_0),by(gvkey)
	}	
	
	drop rank	
	
* Adjustments to AFSI:
	* SALT:
		replace txs = 0 if missing(txs)
	* Depreciation: 
		* Calculate change in the DTL and gross up the amount by the tax rate
		* to estimate tax depreciation related to PPE
		gen l_dtl = L.dtl 
		gen change_dtl = dtl - l_dtl 
		gen gross_up = change_dtl/.21 if fyear > 2017
			replace gross_up = change_dtl/.35 if fyear <= 2017
		* Because not all firms report this amount, estimate PPE based on median:
		gen capex_gross = gross_up/capx 
		egen median_ratio = median(capex_gross)
		gen adj_to_dep = gross_up 
		gen imputed_dep_adj = 0
			replace imputed_dep_adj = 1 if missing(adj_to_dep) & capx != .
		replace adj_to_dep = median_ratio * capx if missing(adj_to_dep)	
		replace dp = dpc if missing(dp)
		* Calculate tax depreciation by adding/subtracting book-tax difference 
		* to/from book tax
		gen tax_dep = dp + adj_to_dep
		replace tax_dep = 0 if missing(tax_dep)
		gen og_dep = dp 
		replace dp = 0 if tax_dep == 0 
	* Pension Adjustment:
		* Caclulate change in the DTA and then gross up by the tax rate
		gen l_dta = L.benefits_dta 
		gen change_dta = benefits_dta - l_dta 
		gen gross_up_dta = change_dta/.21 if fyear > 2017
			replace gross_up = change_dta/.35 if fyear <= 2017
		replace gross_up_dta = 0 if missing(gross_up_dta)
		
	* Adjust AFSI for Verizon, AT&T, T-Mobile, and Dish
		gen spectrum = 0
		replace spectrum = 4380 if tic == "VZ"
		replace spectrum = 3820 if tic == "T"
		replace spectrum = 930 if tic == "TMUS"
		replace spectrum = 1200 if tic == "DISH"	
	* Adjust for insurance gains/losses
		* These are the SIC codes for insurance companies
		gen ins_co = 0
		replace ins_co = 1 if sic == "6311"
		replace ins_co = 1 if sic == "6321"
		replace ins_co = 1 if sic == "6324"
		replace ins_co = 1 if sic == "6331"
		replace ins_co = 1 if sic == "6351"
		replace ins_co = 1 if sic == "6361"
		replace ins_co = 1 if sic == "6399"
		replace ins_co = 1 if sic == "6411"
		gen ins_gain = gliv if ins_co == 1 
		replace ins_gain = 0 if missing(ins_gain)		
* Determine firms in scope:	 
	gen afsix =  pi - txs  + dp - tax_dep  + gross_up_dta - spectrum - ins_gain
	forvalues i = 2010/2022 {
		* This variable is used to determine the look back period of the 
		* applicable corporation test.
		global x = `i' -4
		* Identify the AFSI that can be used in the applicable corporation test 
		gen test_`i' = afsix if fyear < `i' & fyear > $x
		* Calculate average AFSI for the lookback period in each year
		egen app_`i' = mean(test_`i'),by(gvkey)
		gen app_corp_`i' = 0
		replace app_corp_`i' = 1 if app_`i' > 1000 & fyear == `i'
		replace app_corp_`i' = 0 if missing(app_`i') 
		egen xapp = sum(app_corp_`i'),by(gvkey)
		drop app_corp_`i' 
		rename xapp app_corp_`i'
	}	
* We overwrite the saved file so that we have the baseline AFSI that firms
* will end up with. This allows us to keep track of firms' applicable 
* corporation status as the sample is adjusted

save temp, replace
	* Panel B summary table
	keep if fyear == 2021 | fyear == 2022 | fyear == 2020
	* We again drop non-C corporations and non-US firms.
	drop if loc != "USA"
	drop if fic != "USA"
	capture drop X 
	drop if sic == "6798"
	gen X = 1 if strpos(conm,"TRUST")>0
		replace X = 1 if strpos(conm,"LLC")>0
		
	* Drop if 6-digit cusip ends in Y or Z
	gen cusip_6 = substr(cusip, 1,6)
	gen cusip_drop = substr(cusip_6,-1,.)
		replace X = 1 if cusip_drop == "Y" 
		replace X = 1 if cusip_drop == "Z" 
			
	* Drop if last two letters of conm strpos(conm, "LP")> 0
	gen var = substr(conm, -3,.)
		replace X = 1 if strpos(conm, "LLP")> 0 
		replace X = 1 if var == " LP" 	

	drop if X ==1
	keep if app_corp_2022 == 1
	
	label var at "Total Assets"
	label var lt "Total Liabilities"
	label var ni "Net Income"
	label var sale "Sales"
	label var pi "Pretax Income"
	label var pidom "Pretax Domestic Income"
	label var pifo "Pretax Foreign Income"
	label var txfed "Federal Income Tax"
	label var txdfed "Deferred Federal Income Tax"
	label var txfo "Foreign Income Tax"
	label var txdfo "Foreign Deferred Income Tax"
	label var txpd "Cash Taxes Paid"
	label var txs "State and Local Income Taxes"
* This generates the summary statistics of Table 1 Panel B:	
estpost sum at lt ni sale pi pidom pifo txfed txdfed txfo txdfo txpd txs etr cash_etr , detail 
	esttab, cells("count p5 p25 p50 p75 p95 mean sd") noobs sfmt(%12.2fc) 
	eststo clear
	

	* Calculate stats for this:
		use temp, clear
		* This calculates the number of firms with CAMT liability in each year,
		* the average ETR for each firm with CAMT liability in that year 
		* and the average cash tax ETR for each firm with CAMT liability 
		* in that year.
		forvalues i = 2010/2022 {
			gen x_`i' = 0
			replace x_`i' = 1 if camt_liab_`i'_0 > 0 & fyear == `i'
			egen n_`i' = sum(x_`i')
			gen x_etr_`i' = etr if fyear == `i' & camt_liab_`i'_0 > 0
			gen x_cash_etr_`i' = cash_etr if fyear == `i' & camt_liab_`i'_0 > 0
			egen etr_`i' = mean(x_etr_`i')
			egen cash_etr_`i' = mean(x_cash_etr_`i')
		}
		duplicates drop gvkey, force 
		* This calculates aggregate CAMT liability in each year and the number 
		* of firms that are in-scope
		forvalues i = 2010/2022 {
			egen total_camt_`i'_0 = sum(camt_liab_`i'_0)
			rename total_camt_`i'_0 camt_`i'
			egen inscope_`i' = sum(app_corp_`i')
		}
		gen note = "01. Pretax income over $1 billion"
		keep note camt_*  n_* etr_* cash_etr_* inscope*
		duplicates drop note, force 
		save camt_est, replace 
	* Find the firms which expect to pay the most in each year:	
		forvalues i = 2010/2022{
			use temp, clear 
			duplicates drop gvkey, force 
			gsort -camt_liab_`i'_0 
			rename camt_liab_`i'_0 camt_liab_`i'
			gen rank = _n 
			keep if rank < 31
			keep conm camt_liab_`i' rank
			gen note = "01. Pretax income over $1 billion"
			save camt_firms_`i', replace 
			* This allows us to track which firms enter and exit the regime and why
			use temp, clear 
			keep if camt_liab_`i'_0 > 0 & fyear == `i'
			keep if fyear == `i'
			keep gvkey conm 
			duplicates drop gvkey, force 
			save L_`i', replace
		}
* Drop Non-US Companies:
	use temp, clear
	forvalues i = 2010/2022 {
		gen xdrop_`i' = 0
		replace xdrop_`i' = 1 if loc != "USA" & fyear == `i'
		replace xdrop_`i' = 1 if fic != "USA" & fyear == `i'		
		egen drop_`i' = sum(xdrop_`i'),by(gvkey)
		* Replace CAMT liability/App Corp status with zero if the firm is not US 
		replace camt_liab_`i'_0 = 0 if drop_`i' > 0 
		replace app_corp_`i' = 0 if drop_`i' > 0
	}	
	save temp, replace
	
	* Calculate stats for this:
	* We repeat the process to find the number of firms paying CAMT in each year
	*and their respective book and cash ETRs in that year
	forvalues i = 2010/2022 {
		gen x_`i' = 0
		replace x_`i' = 1 if camt_liab_`i'_0 > 0 & fyear == `i'
		egen n_`i' = sum(x_`i')
		gen x_etr_`i' = etr if fyear == `i' & camt_liab_`i'_0 > 0
		gen x_cash_etr_`i' = cash_etr if fyear == `i' & camt_liab_`i'_0 > 0
		egen etr_`i' = mean(x_etr_`i')
		egen cash_etr_`i' = mean(x_cash_etr_`i')
	}
		duplicates drop gvkey, force 
	* This calculates aggregate CAMT liability by year and the number of in-
	* scope firms
	forvalues i = 2010/2022 {
		egen total_camt_`i'_0 = sum(camt_liab_`i'_0)
		rename total_camt_`i'_0 camt_`i'
		egen inscope_`i' = sum(app_corp_`i')
	}
		gen note = "02. Drop non-US companies"
		keep note camt_* n_* etr_* cash_etr_* inscope*
		duplicates drop note, force 
		append using camt_est 
		sort note
		save camt_est, replace 
	* Find the firms which expect to pay the most & which firms drop on/off:
		* For 2022 and the reason why:
		* This dataset will allow you to track which firms drop in/out of CAMT 
		* and why. This is not used directly in the paper
		use temp, clear
		keep if fyear == 2022 
		keep if camt_liab_2022_0 > 0 
		keep gvkey conm 
		merge 1:1 gvkey using L_2022 
		gen dropped = 1 if _merge == 2 
		gen added = 1 if _merge == 1 
		gen kept = 1 if _merge == 3
		foreach i in dropped added kept {
			replace `i' = 0 if missing(`i')
		}
		gen note = "02. Drop non-US companies"
		drop _merge 
		save CAMT_2022, replace 
	forvalues i = 2010/2022 {
		* Which firms paid the most in year X (not used in paper)
		use temp, clear
		duplicates drop gvkey, force
		gsort -camt_liab_`i'_0
		rename camt_liab_`i'_0 camt_liab_`i'
		gen rank = _n 
		keep if rank < 31
		keep conm camt_liab_`i' rank
		gen note = "02. Drop non-US companies"
		append using camt_firms_`i'
		save camt_firms_`i', replace 
	* Which firms dropped on/off in year X:
		use temp, clear
		keep if camt_liab_`i'_0 > 0
		keep if fyear == `i'
		keep gvkey conm		
		merge 1:1 gvkey using L_`i' 
		gen xdropped_`i' = 0
		replace xdropped_`i' = 1 if _merge == 2 
		egen dropped_`i' = sum(xdropped_`i')
		gen xadded_`i' = 0 
		replace xadded_`i' = 1 if _merge == 1
		egen added_`i' = sum(xadded_`i')
		gen note = "02. Drop non-US companies"
		duplicates drop note, force 
		keep note added_`i' dropped_`i' 
		merge 1:1 note using camt_est 
		drop _merge 
		save camt_est, replace 
	* Track which companies drop on/off:
		use temp, clear
		keep if camt_liab_`i'_0 > 0 & fyear == `i'
		keep gvkey conm 
		duplicates drop gvkey, force 
		save L_`i', replace 
	} 

* Drop REITs, LLPs, and Trusts:
	use temp, clear
	* Drop REITs, LLPs, Trusts
	forvalues i = 2010/2022 {
		replace xdrop_`i' = 1 if sic == "6798"
		replace xdrop_`i' = 1 if strpos(conm,"TRUST")>0
		replace xdrop_`i' = 1 if strpos(conm,"LLC")>0
		drop drop_*
		egen drop_`i' = sum(xdrop_`i'),by(gvkey)
	}
			
	* Drop if 6-digit cusip ends in Y or Z
	gen cusip_6 = substr(cusip, 1,6)
	gen cusip_drop = substr(cusip_6,-1,.)
	forvalues i = 2010/2022 {
		replace xdrop_`i' = 1 if cusip_drop == "Y" & fyear == `i'
		replace xdrop_`i' = 1 if cusip_drop == "Z" & fyear == `i'
	}
			
	* Drop if last two letters of conm strpos(conm, "LP")> 0
	gen var = substr(conm, -3,.)
	forvalues i = 2010/2022 {
		replace xdrop_`i' = 1 if strpos(conm, "LLP")> 0 & fyear == `i'
		replace xdrop_`i' = 1 if var == " LP" & fyear == `i'	
		capture drop drop_`i'
		egen drop_`i' = sum(xdrop_`i'),by(gvkey)
		replace camt_liab_`i'_0 = 0 if drop_`i' > 1
		replace app_corp_`i' = 0 if drop_`i' > 0
	}
			
	save temp, replace
* This prepares a file that we later use to match to the rate rec. and DTL/DTAs 
* from Calcbench. We keep only applicable corporations
	keep if app_corp_2022 == 1 
	keep if fyear == 2022
	keep conm cik tic pi 
	duplicates drop conm cik tic, force 
	save rec, replace
	
	* Calculate stats for this:
	use temp, clear 
		* This calculates the number of firms with CAMT liability in each year,
		* the average ETR for each firm with CAMT liability in that year 
		* and the average cash tax ETR for each firm with CAMT liability 
		* in that year.	
	forvalues i = 2010/2022 {
		gen x_`i' = 0
		replace x_`i' = 1 if camt_liab_`i'_0 > 0 & fyear == `i'
		egen n_`i' = sum(x_`i')
		gen x_etr_`i' = etr if fyear == `i' & camt_liab_`i'_0 > 0
		gen x_cash_etr_`i' = cash_etr if fyear == `i' & camt_liab_`i'_0 > 0
		egen etr_`i' = mean(x_etr_`i')
		egen cash_etr_`i' = mean(x_cash_etr_`i')
	}
		* This calculates aggregate CAMT liability in each year and the number 
		* of firms that are in-scope	
		duplicates drop gvkey, force 
	forvalues i = 2010/2022 {
		egen total_camt_`i'_0 = sum(camt_liab_`i'_0)
		rename total_camt_`i'_0 camt_`i'
		egen inscope_`i' = sum(app_corp_`i')
	}
		gen note = "03. Drop REITs, LLPs, LLCs, and trusts"
		keep note camt_* n_* etr_* cash_etr_* inscope*
		duplicates drop note, force 
		append using camt_est 
		sort note
		save camt_est, replace 
	* Find the firms which expect to pay the most & which firms drop on/off:
		* For 2022 and the reason why:
		use temp, clear
		keep if fyear == 2022 
		keep if camt_liab_2022_0 > 0 
		keep gvkey conm 
		merge 1:1 gvkey using L_2022 
		gen dropped = 1 if _merge == 2 
		gen added = 1 if _merge == 1 
		gen kept = 1 if _merge == 3
		foreach i in dropped added kept {
			replace `i' = 0 if missing(`i')
		}
		gen note = "03. Drop REITs, LLPs, LLCs, and trusts"
		drop _merge 
		append using CAMT_2022 
		save CAMT_2022, replace 		
	forvalues i = 2010/2022 {
		* Which firms paid the most in year X (not used in paper)
		use temp, clear
		duplicates drop gvkey, force
		gsort -camt_liab_`i'_0
		rename camt_liab_`i'_0 camt_liab_`i'
		gen rank = _n 
		keep if rank < 31
		keep conm camt_liab_`i' rank
		gen note = "03. Drop REITs, LLPs, LLCs, and trusts"
		append using camt_firms_`i'
		save camt_firms_`i', replace 
	* Which firms dropped on/off in year X:
		use temp, clear
		keep if camt_liab_`i'_0 > 0
		keep if fyear == `i'
		keep gvkey conm		
		merge 1:1 gvkey using L_`i' 
		gen xdropped_`i' = 0
		replace xdropped_`i' = 1 if _merge == 2 
		egen dropped_`i' = sum(xdropped_`i')
		gen xadded_`i' = 0 
		replace xadded_`i' = 1 if _merge == 1
		egen added_`i' = sum(xadded_`i')
		gen note = "03. Drop REITs, LLPs, LLCs, and trusts"
		duplicates drop note, force 
		keep note added_`i' dropped_`i' 
		merge 1:1 note using camt_est 
		drop _merge 
		save camt_est, replace 
	* Track which companies drop on/off:
		use temp, clear
		keep if camt_liab_`i'_0 > 0 & fyear == `i'
		keep gvkey conm 
		duplicates drop gvkey, force 
		save L_`i', replace 
	} 
* Step 3: Adjustment for SALT:
	use temp, clear
*  ORIGINAL PARAMETERS:	
	* Assume SALT is zero if missing current SALT
		replace txs = 0 if missing(txs)
		
	* Deduct SALT from pretax income:
	gen afsi = pi - txs 
	* Drop previously calculated liabilities/tentative taxes
	drop afsi_* tax_paid_* tent_camt_* xcamt_* camt_liab* 
	
	forvalues i = 2010/2022{
		* Calculate annual AFSI
		gen afsi_`i'_0 = pi - txs if fyear == `i' & pi > 0 
		* If AFSI does not exceed $1B, replace with zero
		replace afsi_`i'_0 = 0 if afsi_`i'_0 < 1000		
		* Calculate annual ordinary corporate tax
		gen tax_paid_`i'_0 = fed_tax if fyear == `i' 
		replace tax_paid_`i'_0 = 0 if tax_paid_`i'_0 < 0
		* Calculate tentative minimum tax by multiplying AFSI by 15%
		gen tent_camt_`i'_0 = afsi_`i'_0 * .15 
		* CAMT is the difference between CAMT and ordinary corporate tax
		gen xcamt_liab_`i'_0 = tent_camt_`i'_0 - tax_paid_`i'_0
		* If CAMT is less than zero, meaning federal tax exceeds tent. CAMT,
		* replace with zero
		replace xcamt_liab_`i'_0 = 0 if xcamt_liab_`i'_0 < 0
		replace xcamt_liab_`i'_0 = 0 if fyear != `i'
		egen camt_liab_`i'_0 = sum(xcamt_liab_`i'_0),by(gvkey)
		* Replace CAMT with zero if it is a non-US or non-C corp.
		replace camt_liab_`i'_0 = 0 if drop_`i' > 0 
	}
	save temp, replace	
		
	* Calculate stats for this:
		* This calculates the number of firms with CAMT liability in each year,
		* the average ETR for each firm with CAMT liability in that year 
		* and the average cash tax ETR for each firm with CAMT liability 
		* in that year.	
	forvalues i = 2010/2022 {
		gen x_`i' = 0
		replace x_`i' = 1 if camt_liab_`i'_0 > 0 & fyear == `i'
		egen n_`i' = sum(x_`i')
		gen x_etr_`i' = etr if fyear == `i' & camt_liab_`i'_0 > 0
		gen x_cash_etr_`i' = cash_etr if fyear == `i' & camt_liab_`i'_0 > 0
		egen etr_`i' = mean(x_etr_`i')
		egen cash_etr_`i' = mean(x_cash_etr_`i')
	}
		* This calculates aggregate CAMT liability in each year and the number 
		* of firms that are in-scope	
		duplicates drop gvkey, force 
	forvalues i = 2010/2022 {
		egen total_camt_`i'_0 = sum(camt_liab_`i'_0)
		rename total_camt_`i'_0 camt_`i'
		egen inscope_`i' = sum(app_corp_`i')
	}
		gen note = "04. Adjustment for state and local taxes"
		keep note camt_* n_* etr_* cash_etr_*
		duplicates drop note, force 
		append using camt_est 
		sort note
		save camt_est, replace 
	* Find the firms which expect to pay the most & which firms drop on/off:
		* For 2022 and the reason why:
		use temp, clear
		keep if fyear == 2022 
		keep if camt_liab_2022_0 > 0 
		keep gvkey conm 
		merge 1:1 gvkey using L_2022 
		gen dropped = 1 if _merge == 2 
		gen added = 1 if _merge == 1 
		gen kept = 1 if _merge == 3
		foreach i in dropped added kept {
			replace `i' = 0 if missing(`i')
		}
		gen note = "04. Adjustment for state and local taxes"
		drop _merge 
		append using CAMT_2022 
		save CAMT_2022, replace 
	forvalues i = 2010/2022 {
		* Which firms paid the most in year X (not used in paper)
		use temp, clear
		duplicates drop gvkey, force
		gsort -camt_liab_`i'_0
		rename camt_liab_`i'_0 camt_liab_`i'
		gen rank = _n 
		keep if rank < 31
		keep conm camt_liab_`i' rank
		gen note = "04. Adjustment for state and local taxes"
		append using camt_firms_`i'
		save camt_firms_`i', replace 
	* Which firms dropped on/off in year X:
		use temp, clear
		keep if camt_liab_`i'_0 > 0
		keep if fyear == `i'
		keep gvkey conm		
		merge 1:1 gvkey using L_`i' 
		gen xdropped_`i' = 0
		replace xdropped_`i' = 1 if _merge == 2 
		egen dropped_`i' = sum(xdropped_`i')
		gen xadded_`i' = 0 
		replace xadded_`i' = 1 if _merge == 1
		egen added_`i' = sum(xadded_`i')
		gen note = "04. Adjustment for state and local taxes"
		duplicates drop note, force 
		keep note added_`i' dropped_`i' 
		merge 1:1 note using camt_est 
		drop _merge 
		save camt_est, replace 
	* Track which companies drop on/off:
		use temp, clear
		keep if camt_liab_`i'_0 > 0 & fyear == `i'
		keep gvkey conm 
		duplicates drop gvkey, force 
		save L_`i', replace 
	} 
		
* Step 5: Apply applicable corporation rule. Average AFSI must exceed 1B on average across prior three years:
	use temp, clear
	
	forvalues i = 2010/2022 {
		* We previously calculated whether a firm is an applicable corporation
		* See above.
		replace camt_liab_`i'_0 = 0 if app_corp_`i' == 0 
	}
	
	save temp, replace 
	* Calculate stats for this:
		* This calculates the number of firms with CAMT liability in each year,
		* the average ETR for each firm with CAMT liability in that year 
		* and the average cash tax ETR for each firm with CAMT liability 
		* in that year.	
	forvalues i = 2013/2022 {
		gen x_`i' = 0
		replace x_`i' = 1 if camt_liab_`i'_0 > 0 & fyear == `i'
		egen n_`i' = sum(x_`i')
		gen x_etr_`i' = etr if fyear == `i' & camt_liab_`i'_0 > 0
		gen x_cash_etr_`i' = cash_etr if fyear == `i' & camt_liab_`i'_0 > 0
		egen etr_`i' = mean(x_etr_`i')
		egen cash_etr_`i' = mean(x_cash_etr_`i')
	}
		* This calculates aggregate CAMT liability in each year and the number 
		* of firms that are in-scope
		duplicates drop gvkey, force 
	forvalues i = 2013/2022 {
		egen total_camt_`i'_0 = sum(camt_liab_`i'_0)
		rename total_camt_`i'_0 camt_`i'
	}
		gen note = "05. AFSI must exceed $1B on average for prior 3 FYs"
		keep note camt_* n_* etr_* cash_etr_*
		duplicates drop note, force 
		append using camt_est 
		sort note
		save camt_est, replace 
	* Find the firms which expect to pay the most & which firms drop on/off:
		* For 2022 and the reason why:
		use temp, clear
		keep if fyear == 2022 
		keep if camt_liab_2022_0 > 0 
		keep gvkey conm 
		merge 1:1 gvkey using L_2022 
		gen dropped = 1 if _merge == 2 
		gen added = 1 if _merge == 1 
		gen kept = 1 if _merge == 3
		foreach i in dropped added kept {
			replace `i' = 0 if missing(`i')
		}
		gen note = "05. AFSI must exceed $1B on average for prior 3 FYs"
		drop _merge 
		append using CAMT_2022 
		save CAMT_2022, replace 
	forvalues i = 2013/2022 {
		* Which firms paid the most in year X (not used in paper)
		use temp, clear
		duplicates drop gvkey, force
		gsort -camt_liab_`i'_0
		rename camt_liab_`i'_0 camt_liab_`i'
		gen rank = _n 
		keep if rank < 31
		keep conm camt_liab_`i' rank
		gen note = "05. AFSI must exceed $1B on average for prior 3 FYs"
		append using camt_firms_`i'
		save camt_firms_`i', replace 
	* Which firms dropped on/off in year X:
		use temp, clear
		keep if camt_liab_`i'_0 > 0
		keep if fyear == `i'
		keep gvkey conm		
		merge 1:1 gvkey using L_`i' 
		gen xdropped_`i' = 0
		replace xdropped_`i' = 1 if _merge == 2 
		egen dropped_`i' = sum(xdropped_`i')
		gen xadded_`i' = 0 
		replace xadded_`i' = 1 if _merge == 1
		egen added_`i' = sum(xadded_`i')
		gen note = "05. AFSI must exceed $1B on average for prior 3 FYs"
		duplicates drop note, force 
		keep note added_`i' dropped_`i' 
		merge 1:1 note using camt_est 
		drop _merge 
		save camt_est, replace 
	* Track which companies drop on/off:
		use temp, clear
		keep if camt_liab_`i'_0 > 0 & fyear == `i'
		keep gvkey conm 
		duplicates drop gvkey, force 
		save L_`i', replace 
	} 
			
* Step 6: Adjusted net income for tax depreciation:
	use temp, clear
	
	* Depreciation adjustment:
		sort gvkeyid fyear
		xtset gvkeyid fyear 
	* Add book depreciation back to AFSI and deduct estimated tax depreciation
		* Note: tax_dep was calculated in an earlier step.
	replace afsi = pi - txs + dp - tax_dep 
	forvalues i = 2013/2022 {
		* Calculate annual AFSI
		gen afsi_`i'_2 = pi - txs + dp - tax_dep if fyear == `i' & pi > 0 
		replace afsi_`i'_2 = 0 if afsi_`i'_2 < 0
		* Calculate annual ordinary corporate tax
		gen tax_paid_`i'_2 = fed_tax if fyear == `i'
		replace tax_paid_`i'_2 = 0 if tax_paid_`i'_2 < 0	
		* Calculate tentative minimum tax by multiplying AFSI by 15%
		gen tent_camt_`i'_2 = afsi_`i'_2 * .15 
		* CAMT is the difference between CAMT and ordinary corporate tax
		gen xcamt_liab_`i'_2 = tent_camt_`i'_2 - tax_paid_`i'_2
		* If CAMT is less than zero, meaning federal tax exceeds tent. CAMT,
		* replace with zero
		replace xcamt_liab_`i'_2 = 0 if xcamt_liab_`i'_2 < 0
		egen camt_liab_`i'_2 = sum(xcamt_liab_`i'_2),by(gvkey)
		* Replace CAMT with zero if it is a non-US or non-C corp.
		replace camt_liab_`i'_2 = 0 if drop_`i' > 0				
	}	
	drop *_0
	forvalues i = 2013/2022 {
		* If avg. AFSI does not exceed $1B, replace with zero
		replace camt_liab_`i'_2 = 0 if app_corp_`i' == 0 
		rename camt_liab_`i'_2 camt_liab_`i'_0 
	}		
	save temp, replace

	* Calculate stats for this:
		* This calculates the number of firms with CAMT liability in each year,
		* the average ETR for each firm with CAMT liability in that year 
		* and the average cash tax ETR for each firm with CAMT liability 
		* in that year.	
	forvalues i = 2013/2022 {
		gen x_`i' = 0
		replace x_`i' = 1 if camt_liab_`i'_0 > 0 & fyear == `i'
		egen n_`i' = sum(x_`i')
		gen x_etr_`i' = etr if fyear == `i' & camt_liab_`i'_0 > 0
		gen x_cash_etr_`i' = cash_etr if fyear == `i' & camt_liab_`i'_0 > 0
		egen etr_`i' = mean(x_etr_`i')
		egen cash_etr_`i' = mean(x_cash_etr_`i')
	}
		* This calculates aggregate CAMT liability in each year and the number 
		* of firms that are in-scope	
		duplicates drop gvkey, force 
	forvalues i = 2013/2022 {
		egen total_camt_`i'_0 = sum(camt_liab_`i'_0)
		rename total_camt_`i'_0 camt_`i'
	}
		gen note = "06. Adjustment for tax depreciation"
		keep note camt_* n_* etr_* cash_etr_*
		duplicates drop note, force 
		append using camt_est 
		sort note
		save camt_est, replace 
	* Find the firms which expect to pay the most & which firms drop on/off:
		* For 2022 and the reason why:
		use temp, clear
		keep if fyear == 2022 
		keep if camt_liab_2022_0 > 0 
		keep gvkey conm 
		merge 1:1 gvkey using L_2022 
		gen dropped = 1 if _merge == 2 
		gen added = 1 if _merge == 1 
		gen kept = 1 if _merge == 3
		foreach i in dropped added kept {
			replace `i' = 0 if missing(`i')
		}
		gen note = "06. Adjustment for tax depreciation"
		drop _merge 
		append using CAMT_2022 
		save CAMT_2022, replace
	forvalues i = 2013/2022 {
		* Which firms paid the most in year X (not used in paper)
		use temp, clear
		duplicates drop gvkey, force
		gsort -camt_liab_`i'_0
		rename camt_liab_`i'_0 camt_liab_`i'
		gen rank = _n 
		keep if rank < 31
		keep conm camt_liab_`i' rank
		gen note = "06. Adjustment for tax depreciation"
		append using camt_firms_`i'
		save camt_firms_`i', replace 
	* Which firms dropped on/off in year X:
		use temp, clear
		keep if camt_liab_`i'_0 > 0
		keep if fyear == `i'
		keep gvkey conm		
		merge 1:1 gvkey using L_`i' 
		gen xdropped_`i' = 0
		replace xdropped_`i' = 1 if _merge == 2 
		egen dropped_`i' = sum(xdropped_`i')
		gen xadded_`i' = 0 
		replace xadded_`i' = 1 if _merge == 1
		egen added_`i' = sum(xadded_`i')
		gen note = "06. Adjustment for tax depreciation"
		duplicates drop note, force 
		keep note added_`i' dropped_`i' 
		merge 1:1 note using camt_est 
		drop _merge 
		save camt_est, replace 
	* Track which companies drop on/off:
		use temp, clear
		keep if camt_liab_`i'_0 > 0 & fyear == `i'
		keep gvkey conm 
		duplicates drop gvkey, force 
		save L_`i', replace 
	} 
			
* Step 7: Pension DTA adjustment:
	use temp, clear

	drop afsi_20* tax_paid_* tent_cam* xcamt* camt_* 
	
	forvalues i = 2013/2022 {
		* Calculate annual AFSI - incorporate DB pension adj. (gross_up_dta)
			* Note gross_up_dta is calculated in an earlier step.
		gen afsi_`i'_2 = pi - txs + dp - tax_dep + gross_up_dta if fyear == `i' & pi > 0
		replace afsi_`i'_2 = 0 if afsi_`i'_2 < 0 
		* Calculate annual ordinary corporate tax
		gen tax_paid_`i'_2 = fed_tax if fyear == `i'
		replace tax_paid_`i'_2 = 0 if tax_paid_`i'_2 < 0
		* Calculate tentative minimum tax by multiplying AFSI by 15%
		gen tent_camt_`i'_2 = afsi_`i'_2 * .15 
		* CAMT is the difference between CAMT and ordinary corporate tax
		gen xcamt_liab_`i'_2 = tent_camt_`i'_2 - tax_paid_`i'_2
		* If CAMT is less than zero, meaning federal tax exceeds tent. CAMT,
		* replace with zero
		replace xcamt_liab_`i'_2 = 0 if xcamt_liab_`i'_2 < 0
		egen camt_liab_`i'_2 = sum(xcamt_liab_`i'_2),by(gvkey)
		* Replace CAMT with zero if it is a non-US or non-C corp.
		replace camt_liab_`i'_2 = 0 if drop_`i' > 0
	}
	replace afsi =  pi - txs + dp - tax_dep + gross_up_dta
	forvalues i = 2013/2022 {
		* If avg. AFSI does not exceed $1B, replace with zero
		replace camt_liab_`i'_2 = 0 if app_corp_`i' == 0 
		rename camt_liab_`i'_2 camt_liab_`i'_0 
	}			
	save temp, replace		
		
	* Calculate stats for this:
		* This calculates the number of firms with CAMT liability in each year,
		* the average ETR for each firm with CAMT liability in that year 
		* and the average cash tax ETR for each firm with CAMT liability 
		* in that year.	
	forvalues i = 2013/2022 {
		gen x_`i' = 0
		replace x_`i' = 1 if camt_liab_`i'_0 > 0 & fyear == `i'
		egen n_`i' = sum(x_`i')
		gen x_etr_`i' = etr if fyear == `i' & camt_liab_`i'_0 > 0
		gen x_cash_etr_`i' = cash_etr if fyear == `i' & camt_liab_`i'_0 > 0
		egen etr_`i' = mean(x_etr_`i')
		egen cash_etr_`i' = mean(x_cash_etr_`i')
	}
		* This calculates aggregate CAMT liability in each year and the number 
		* of firms that are in-scope	
		duplicates drop gvkey, force 
	forvalues i = 2013/2022 {
		egen total_camt_`i'_0 = sum(camt_liab_`i'_0)
		rename total_camt_`i'_0 camt_`i'
	}
		gen note = "07. Pension adjustment"
		keep note camt_* n_* etr_* cash_etr_*
		duplicates drop note, force 
		append using camt_est 
		sort note
		save camt_est, replace 
	* Find the firms which expect to pay the most & which firms drop on/off:
		* For 2022 and the reason why:
		use temp, clear
		keep if fyear == 2022 
		keep if camt_liab_2022_0 > 0 
		keep gvkey conm 
		merge 1:1 gvkey using L_2022 
		gen dropped = 1 if _merge == 2 
		gen added = 1 if _merge == 1 
		gen kept = 1 if _merge == 3
		foreach i in dropped added kept {
			replace `i' = 0 if missing(`i')
		}
		gen note = "07. Pension adjustment"
		drop _merge 
		append using CAMT_2022 
		save CAMT_2022, replace
	forvalues i = 2013/2022 {
		* Which firms paid the most in year X (not used in paper)
		use temp, clear
		duplicates drop gvkey, force
		gsort -camt_liab_`i'_0
		rename camt_liab_`i'_0 camt_liab_`i'
		gen rank = _n 
		keep if rank < 31
		keep conm camt_liab_`i' rank
		gen note = "07. Pension adjustment"
		append using camt_firms_`i'
		save camt_firms_`i', replace 
	* Which firms dropped on/off in year X:
		use temp, clear
		keep if camt_liab_`i'_0 > 0
		keep if fyear == `i'
		keep gvkey conm		
		merge 1:1 gvkey using L_`i' 
		gen xdropped_`i' = 0
		replace xdropped_`i' = 1 if _merge == 2 
		egen dropped_`i' = sum(xdropped_`i')
		gen xadded_`i' = 0 
		replace xadded_`i' = 1 if _merge == 1
		egen added_`i' = sum(xadded_`i')
		gen note = "07. Pension adjustment"
		duplicates drop note, force 
		keep note added_`i' dropped_`i' 
		merge 1:1 note using camt_est 
		drop _merge 
		save camt_est, replace 
	* Track which companies drop on/off:
		use temp, clear
		keep if camt_liab_`i'_0 > 0 & fyear == `i'
		keep gvkey conm 
		duplicates drop gvkey, force 
		save L_`i', replace 
	} 
		
* Step 8: Adjust for Spectrum:
	use temp, clear

	drop tax_paid* tent_cam* xcamt* camt_liab* 	
	forvalues i = 2013/2022 {
		* Calculate annual AFSI - adding in consideration of spectrum 
		* amortization. This amount was determined in an earlier step 
		replace afsi_`i'_2 = afsi_`i'_2 - spectrum
		replace afsi_`i'_2 = 0 if afsi_`i'_2 < 0 
		* Calculate annual ordinary corporate tax
		gen tax_paid_`i'_2 = fed_tax if fyear == `i' 
		replace tax_paid_`i'_2 = 0 if tax_paid_`i'_2 < 0
		* Calculate tentative minimum tax by multiplying AFSI by 15%
		gen tent_camt_`i'_2 = afsi_`i'_2 * .15 
		* CAMT is the difference between CAMT and ordinary corporate tax
		gen xcamt_liab_`i'_2 = tent_camt_`i'_2 - tax_paid_`i'_2
		* If CAMT is less than zero, meaning federal tax exceeds tent. CAMT,
		* replace with zero
		replace xcamt_liab_`i'_2 = 0 if xcamt_liab_`i'_2 < 0
		egen camt_liab_`i'_2 = sum(xcamt_liab_`i'_2),by(gvkey)
		* Replace CAMT with zero if it is a non-US or non-C corp.
		replace camt_liab_`i'_2 = 0 if drop_`i' >0
	}
	replace afsi =  pi - txs + dp - tax_dep + gross_up_dta - spectrum
	forvalues i = 2013/2022 {
		* If avg. AFSI does not exceed $1B, replace with zero
		replace camt_liab_`i'_2 = 0 if app_corp_`i' == 0 
		rename camt_liab_`i'_2 camt_liab_`i'_0 
	}					
	save temp, replace		
	
	* Calculate stats for this:
		* This calculates the number of firms with CAMT liability in each year,
		* the average ETR for each firm with CAMT liability in that year 
		* and the average cash tax ETR for each firm with CAMT liability 
		* in that year.	
	forvalues i = 2013/2022 {
		gen x_`i' = 0
		replace x_`i' = 1 if camt_liab_`i'_0 > 0 & fyear == `i'
		egen n_`i' = sum(x_`i')
		gen x_etr_`i' = etr if fyear == `i' & camt_liab_`i'_0 > 0
		gen x_cash_etr_`i' = cash_etr if fyear == `i' & camt_liab_`i'_0 > 0
		egen etr_`i' = mean(x_etr_`i')
		egen cash_etr_`i' = mean(x_cash_etr_`i')
	}
		* This calculates aggregate CAMT liability in each year and the number 
		* of firms that are in-scope	
		duplicates drop gvkey, force 
	forvalues i = 2013/2022 {
		egen total_camt_`i'_0 = sum(camt_liab_`i'_0)
		rename total_camt_`i'_0 camt_`i'
	}
		gen note = "08. Deduct spectrum amortization from AFSI"
		keep note camt_* n_* etr_* cash_etr_*
		duplicates drop note, force 
		append using camt_est 
		sort note
		save camt_est, replace 
	* Find the firms which expect to pay the most & which firms drop on/off:
		* For 2022 and the reason why:
		use temp, clear
		keep if fyear == 2022 
		keep if camt_liab_2022_0 > 0 
		keep gvkey conm 
		merge 1:1 gvkey using L_2022 
		gen dropped = 1 if _merge == 2 
		gen added = 1 if _merge == 1 
		gen kept = 1 if _merge == 3
		foreach i in dropped added kept {
			replace `i' = 0 if missing(`i')
		}
		gen note = "08. Deduct spectrum amortization from AFSI"
		drop _merge 
		append using CAMT_2022 
		save CAMT_2022, replace
	forvalues i = 2013/2022 {
		* Which firms paid the most in year X (not used in paper)
		use temp, clear
		duplicates drop gvkey, force
		gsort -camt_liab_`i'_0
		rename camt_liab_`i'_0 camt_liab_`i'
		gen rank = _n 
		keep if rank < 31
		keep conm camt_liab_`i' rank
		gen note = "08. Deduct spectrum amortization from AFSI"
		append using camt_firms_`i'
		save camt_firms_`i', replace 
	* Which firms dropped on/off in year X:
		use temp, clear
		keep if camt_liab_`i'_0 > 0
		keep if fyear == `i'
		keep gvkey conm		
		merge 1:1 gvkey using L_`i' 
		gen xdropped_`i' = 0
		replace xdropped_`i' = 1 if _merge == 2 
		egen dropped_`i' = sum(xdropped_`i')
		gen xadded_`i' = 0 
		replace xadded_`i' = 1 if _merge == 1
		egen added_`i' = sum(xadded_`i')
		gen note = "08. Deduct spectrum amortization from AFSI"
		duplicates drop note, force 
		keep note added_`i' dropped_`i' 
		merge 1:1 note using camt_est 
		drop _merge 
		save camt_est, replace 
	* Track which companies drop on/off:
		use temp, clear
		keep if camt_liab_`i'_0 > 0 & fyear == `i'
		keep gvkey conm 
		duplicates drop gvkey, force 
		save L_`i', replace 
	} 
	
* Remove unrealized gains and losses for insurance companies:
	use temp, clear 
	drop tax_paid* tent_cam* xcamt* camt_liab* 	
			
	forvalues i = 2013/2022 {
		* Calculate annual AFSI - Incorporate gains/losses for insurance co.'s 
		replace afsi_`i'_2 = afsi_`i'_2 - ins_gain
		replace afsi_`i'_2 = 0 if afsi_`i'_2 < 0 
		* Calculate annual ordinary corporate tax
		gen tax_paid_`i'_2 = fed_tax if fyear == `i' 
		replace tax_paid_`i'_2 = 0 if tax_paid_`i'_2 < 0
		* Calculate tentative minimum tax by multiplying AFSI by 15%
		gen tent_camt_`i'_2 = afsi_`i'_2 * .15 
		* CAMT is the difference between CAMT and ordinary corporate tax
		gen xcamt_liab_`i'_2 = tent_camt_`i'_2 - tax_paid_`i'_2
		* If CAMT is less than zero, meaning federal tax exceeds tent. CAMT,
		* replace with zero
		replace xcamt_liab_`i'_2 = 0 if xcamt_liab_`i'_2 < 0
		egen camt_liab_`i'_2 = sum(xcamt_liab_`i'_2),by(gvkey)
		* Replace CAMT with zero if it is a non-US or non-C corp.
		replace camt_liab_`i'_2 = 0 if drop_`i' >0
	}
	* Note: ins_gain is calculated in an earlier step 
	replace afsi =  pi - txs + dp - tax_dep + gross_up_dta - spectrum - ins_gain
	forvalues i = 2013/2022 {
		* If avg. AFSI does not exceed $1B, replace with zero
		replace camt_liab_`i'_2 = 0 if app_corp_`i' == 0 
		rename camt_liab_`i'_2 camt_liab_`i'_0 
	}	
		
	save temp, replace	
	* Calculate stats for this:
		* This calculates the number of firms with CAMT liability in each year,
		* the average ETR for each firm with CAMT liability in that year 
		* and the average cash tax ETR for each firm with CAMT liability 
		* in that year.	
	forvalues i = 2013/2022 {
		gen x_`i' = 0
		replace x_`i' = 1 if camt_liab_`i'_0 > 0 & fyear == `i'
		egen n_`i' = sum(x_`i')
		gen x_etr_`i' = etr if fyear == `i' & camt_liab_`i'_0 > 0
		gen x_cash_etr_`i' = cash_etr if fyear == `i' & camt_liab_`i'_0 > 0
		egen etr_`i' = mean(x_etr_`i')
		egen cash_etr_`i' = mean(x_cash_etr_`i')
	}
		* This calculates aggregate CAMT liability in each year and the number 
		* of firms that are in-scope	
		duplicates drop gvkey, force 
	forvalues i = 2013/2022 {
		egen total_camt_`i'_0 = sum(camt_liab_`i'_0)
		rename total_camt_`i'_0 camt_`i'
	}
		gen note = "09. Adjust for treatment of investment gains for insurance companies"
		keep note camt_* n_* etr_* cash_etr_*
		duplicates drop note, force 
		append using camt_est 
		sort note
		save camt_est, replace 
	* Find the firms which expect to pay the most & which firms drop on/off:
		* For 2022 and the reason why:
		use temp, clear
		keep if fyear == 2022 
		keep if camt_liab_2022_0 > 0 
		keep gvkey conm 
		merge 1:1 gvkey using L_2022 
		gen dropped = 1 if _merge == 2 
		gen added = 1 if _merge == 1 
		gen kept = 1 if _merge == 3
		foreach i in dropped added kept {
			replace `i' = 0 if missing(`i')
		}
		gen note = "09. Adjust for treatment of investment gains for insurance companies"
		drop _merge 
		append using CAMT_2022 
		save CAMT_2022, replace
	forvalues i = 2013/2022 {
		* Which firms paid the most in year X (not used in paper)
		use temp, clear
		duplicates drop gvkey, force
		gsort -camt_liab_`i'_0
		rename camt_liab_`i'_0 camt_liab_`i'
		gen rank = _n 
		keep if rank < 31
		keep conm camt_liab_`i' rank
		gen note = "09. Adjust for treatment of investment gains for insurance companies"
		append using camt_firms_`i'
		save camt_firms_`i', replace 
	* Which firms dropped on/off in year X:
		use temp, clear
		keep if camt_liab_`i'_0 > 0
		keep if fyear == `i'
		keep gvkey conm		
		merge 1:1 gvkey using L_`i' 
		gen xdropped_`i' = 0
		replace xdropped_`i' = 1 if _merge == 2 
		egen dropped_`i' = sum(xdropped_`i')
		gen xadded_`i' = 0 
		replace xadded_`i' = 1 if _merge == 1
		egen added_`i' = sum(xadded_`i')
		gen note = "09. Adjust for treatment of investment gains for insurance companies"
		duplicates drop note, force 
		keep note added_`i' dropped_`i' 
		merge 1:1 note using camt_est 
		drop _merge 
		save camt_est, replace 
	* Track which companies drop on/off:
		use temp, clear
		keep if camt_liab_`i'_0 > 0 & fyear == `i'
		keep gvkey conm 
		duplicates drop gvkey, force 
		save L_`i', replace 
	} 	
	
	
* Allow for loss carryforwards of AFSI beginning 2020:
	* Net operating losses and calculate AFSI
	use temp, clear
	xtset gvkeyid fyear
	foreach i in ni pi dp tax_dep gross_up_dta spectrum {
		replace `i' = 0 if missing(`i')
	}
	* Calculate annual AFSI - Incorporate losses:
	replace afsi = pi - txs + dp - tax_dep + gross_up_dta - spectrum - ins_gain
	* If there is an AFSI loss in 2012, it gets counted against 2013. If the 
	* difference is negative, this amount is carried forward as a loss into 
	* subsequent years.
	forvalues i = 2013/2022 {
		gen L_`i' = L.afsi if L.afsi < 0 & fyear == `i'
		replace L_`i' = 0 if missing(L_`i')
		replace afsi = afsi + L_`i' if fyear == `i'
	}	
	
	forvalues i = 2013/2022 {
		gen afsi_`i'_3 = afsi if fyear == `i'
		replace afsi_`i'_3 = 0 if missing(afsi_`i'_3)
		replace afsi_`i'_3 = 0 if afsi_`i'_3 < 0 
		* Calculate annual ordinary corporate tax
		gen tax_paid_`i'_3 = fed_tax if fyear == `i' 
		replace tax_paid_`i'_3 = 0 if tax_paid_`i'_3 < 0
		* Calculate tentative minimum tax by multiplying AFSI by 15%
		gen tent_camt_`i'_3 = afsi_`i'_3 * .15 
		* CAMT is the difference between CAMT and ordinary corporate tax
		gen xcamt_liab_`i'_3 = tent_camt_`i'_3 - tax_paid_`i'_3
		* If CAMT is less than zero, meaning federal tax exceeds tent. CAMT,
		* replace with zero
		replace xcamt_liab_`i'_3 = 0 if xcamt_liab_`i'_3 < 0
		replace xcamt_liab_`i'_3 = 0 if fyear != `i'
		egen camt_liab_`i'_3 = sum(xcamt_liab_`i'_3),by(gvkey)
		* Replace CAMT with zero if it is a non-US or non-C corp.
		replace camt_liab_`i'_3 = 0 if drop_`i' > 0 
	}	

	forvalues i = 2013/2022 {
		* If avg. AFSI does not exceed $1B, replace with zero
		replace camt_liab_`i'_3 = 0 if app_corp_`i' == 0 
	}
	save temp, replace
	
	* Calculate stats for this:
		* This calculates the number of firms with CAMT liability in each year,
		* the average ETR for each firm with CAMT liability in that year 
		* and the average cash tax ETR for each firm with CAMT liability 
		* in that year.
	forvalues i = 2013/2022 {
		gen x_`i' = 0
		replace x_`i' = 1 if camt_liab_`i'_3 > 0 & fyear == `i'
		egen n_`i' = sum(x_`i')
		gen x_etr_`i' = etr if fyear == `i' & camt_liab_`i'_3 > 0
		gen x_cash_etr_`i' = cash_etr if fyear == `i' & camt_liab_`i'_3 > 0
		egen etr_`i' = mean(x_etr_`i')
		egen cash_etr_`i' = mean(x_cash_etr_`i')
	}
		* This calculates aggregate CAMT liability in each year and the number 
		* of firms that are in-scope	
		duplicates drop gvkey, force 
	forvalues i = 2013/2022 {
		egen total_camt_`i'_3 = sum(camt_liab_`i'_3)
		rename total_camt_`i'_3 camt_`i'
	}
		gen note = "10. Allow for carryforward of AFSI losses"
		keep note camt_* n_* etr_* cash_etr_*
		duplicates drop note, force 
		append using camt_est 
		sort note
		save camt_est, replace 
	* Find the firms which expect to pay the most & which firms drop on/off:
		* For 2022 and the reason why:
		use temp, clear
		keep if fyear == 2022 
		keep if camt_liab_2022_3 > 0 
		keep gvkey conm 
		merge 1:1 gvkey using L_2022 
		gen dropped = 1 if _merge == 2 
		gen added = 1 if _merge == 1 
		gen kept = 1 if _merge == 3
		foreach i in dropped added kept {
			replace `i' = 0 if missing(`i')
		}
		gen note = "10. Allow for carryforward of AFSI losses"
		drop _merge 
		append using CAMT_2022 
		save CAMT_2022, replace
	forvalues i = 2013/2022 {
		* Which firms paid the most in year X (not used in paper)
		use temp, clear
		duplicates drop gvkey, force
		gsort -camt_liab_`i'_3
		rename camt_liab_`i'_3 camt_liab_`i'
		gen rank = _n 
		keep if rank < 31
		keep conm camt_liab_`i' rank
		gen note = "10. Allow for carryforward of AFSI losses"
		append using camt_firms_`i'
		save camt_firms_`i', replace 
	* Which firms dropped on/off in year X:
		use temp, clear
		keep if camt_liab_`i'_3 > 0
		keep if fyear == `i'
		keep gvkey conm		
		merge 1:1 gvkey using L_`i' 
		gen xdropped_`i' = 0
		replace xdropped_`i' = 1 if _merge == 2 
		egen dropped_`i' = sum(xdropped_`i')
		gen xadded_`i' = 0 
		replace xadded_`i' = 1 if _merge == 1
		egen added_`i' = sum(xadded_`i')
		gen note = "10. Allow for carryforward of AFSI losses"
		duplicates drop note, force 
		keep note added_`i' dropped_`i' 
		merge 1:1 note using camt_est 
		drop _merge 
		save camt_est, replace 
	* Track which companies drop on/off:
		use temp, clear
		keep if camt_liab_`i'_3 > 0 & fyear == `i'
		keep gvkey conm 
		duplicates drop gvkey, force 
		save L_`i', replace 
	} 

* Limit the carryforward of losses to 80% of AFSI:
	* Net operating losses and calculate AFSI
	use temp, clear
	foreach i in ni pi txs dp tax_dep gross_up_dta spectrum {
		replace `i' = 0 if missing(`i')
	}
	replace afsi = pi - txs + dp - tax_dep + gross_up_dta - spectrum - ins_gain
	* Calculate the limit on carryforward AFSI losses by multiplying 80% by 
	* current year AFSI 
	gen loss_limit = -1 * (.8 * afsi ) if afsi > 0
	* Create a variable to keep track of carryforward losses if the loss carry-
	* forward is limited.
	gen loss_bank = 0 
	
	drop L_* afsi_* tax_paid* tent_camt_* xcamt_* camt_*   
* Original loss calculation
	gen afsi2 = afsi 
	gen afsi2x = afsi 
	forvalues i = 2013/2022 {
		* Calculate carryforward loss:
		gen L2_`i' = L.afsi2 if L.afsi2 < 0 & fyear == `i'
		replace L2_`i' = 0 if missing(L2_`i')
		replace afsi2 = afsi2 + L2_`i' if fyear == `i'
	}	
		
	xtset gvkeyid fyear
	forvalues i = 2013/2022 {
		gen L_`i' = L.afsi if L.afsi < 0 & fyear == `i'
		replace L_`i' = 0 if missing(L_`i')
		replace L_`i' = L_`i' + L.loss_bank if L.loss_bank != .
		gen l_limit_`i' = 0
		replace l_limit_`i' = 1 if loss_limit > L_`i' & fyear == `i' & afsi > 0
		replace afsi = afsi + L_`i' if fyear == `i' & l_limit_`i' == 0 
		* Apply 80% limitation on loss carryforward:
		* Calculate annual AFSI
			replace afsi = afsi * .2 if fyear == `i' & l_limit_`i' == 1 & afsi > 0 
			replace L_`i' = L_`i' - loss_limit if fyear == `i' & l_limit_`i' == 1
			replace loss_bank = L_`i' if fyear == `i' & l_limit_`i' == 1
	}
	
	forvalues i = 2013/2022 {
		gen afsi_`i'_3 = afsi if fyear == `i'
		replace afsi_`i'_3 = 0 if missing(afsi_`i'_3)
		replace afsi_`i'_3 = 0 if afsi_`i'_3 < 0 
		* Calculate annual ordinary corporate tax
		gen tax_paid_`i'_3 = fed_tax if fyear == `i' 
		replace tax_paid_`i'_3 = 0 if tax_paid_`i'_3 < 0
		* Calculate tentative minimum tax by multiplying AFSI by 15%
		gen tent_camt_`i'_3 = afsi_`i'_3 * .15 
		* CAMT is the difference between CAMT and ordinary corporate tax
		gen xcamt_liab_`i'_3 = tent_camt_`i'_3 - tax_paid_`i'_3
		* If CAMT is less than zero, meaning federal tax exceeds tent. CAMT,
		* replace with zero
		replace xcamt_liab_`i'_3 = 0 if xcamt_liab_`i'_3 < 0
		replace xcamt_liab_`i'_3 = 0 if fyear != `i'
		egen camt_liab_`i'_3 = sum(xcamt_liab_`i'_3),by(gvkey)
		* Replace CAMT with zero if it is a non-US or non-C corp.
		replace camt_liab_`i'_3 = 0 if drop_`i' >0
	}	
	* This is not used in the paper. It's a check on the impact that losses 
	* have on CAMT liability
	forvalues i = 2013/2022 {
		gen NL_afsi_`i' = afsi2 if fyear == `i'
		replace NL_afsi_`i' = 0 if missing(NL_afsi_`i')
		replace NL_afsi_`i' = 0 if NL_afsi_`i' < 0 
		gen NL_tax_paid_`i' = fed_tax if fyear == `i' 
		replace NL_tax_paid_`i' = 0 if NL_tax_paid_`i' < 0
		gen NL_tent_camt_`i' = NL_afsi_`i' * .15 
		gen NL_xcamt_liab_`i' = NL_tent_camt_`i' - NL_tax_paid_`i'
		replace NL_xcamt_liab_`i' = 0 if xcamt_liab_`i' < 0
		replace NL_xcamt_liab_`i' = 0 if fyear != `i'
		egen NL_camt_liab_`i' = sum(NL_xcamt_liab_`i'),by(gvkey)
		replace NL_camt_liab_`i' = 0 if drop_`i' >0
	}	
		
	forvalues i = 2013/2022 {
		* If avg. AFSI does not exceed $1B, replace with zero
		replace camt_liab_`i'_3 = 0 if app_corp_`i' == 0 
	}
	
	save temp, replace
	
	* Calculate stats for this:
		* This calculates the number of firms with CAMT liability in each year,
		* the average ETR for each firm with CAMT liability in that year 
		* and the average cash tax ETR for each firm with CAMT liability 
		* in that year.	
	forvalues i = 2013/2022 {
		gen x_`i' = 0
		replace x_`i' = 1 if camt_liab_`i'_3 > 0 & fyear == `i'
		egen n_`i' = sum(x_`i')
		gen x_etr_`i' = etr if fyear == `i' & camt_liab_`i'_3 > 0
		gen x_cash_etr_`i' = cash_etr if fyear == `i' & camt_liab_`i'_3 > 0
		egen etr_`i' = mean(x_etr_`i')
		egen cash_etr_`i' = mean(x_cash_etr_`i')
	}
		* This calculates aggregate CAMT liability in each year and the number 
		* of firms that are in-scope	
		duplicates drop gvkey, force 
	forvalues i = 2013/2022 {
		egen total_camt_`i'_3 = sum(camt_liab_`i'_3)
		rename total_camt_`i'_3 camt_`i'
	}
		gen note = "11. 80% limitation on carryforward of losses"
		keep note camt_* n_* etr_* cash_etr_*
		duplicates drop note, force 
		append using camt_est 
		sort note
		save camt_est, replace 
	* Find the firms which expect to pay the most & which firms drop on/off:
		* For 2022 and the reason why:
		use temp, clear
		keep if fyear == 2022 
		keep if camt_liab_2022_3 > 0 
		keep gvkey conm 
		merge 1:1 gvkey using L_2022 
		gen dropped = 1 if _merge == 2 
		gen added = 1 if _merge == 1 
		gen kept = 1 if _merge == 3
		foreach i in dropped added kept {
			replace `i' = 0 if missing(`i')
		}
		gen note = "11. 80% limitation on carryforward of losses"
		drop _merge 
		append using CAMT_2022 
		save CAMT_2022, replace
	forvalues i = 2013/2022 {
		* Which firms paid the most in year X (not used in paper)
		use temp, clear
		duplicates drop gvkey, force
		gsort -camt_liab_`i'_3
		rename camt_liab_`i'_3 camt_liab_`i'
		gen rank = _n 
		keep if rank < 31
		keep conm camt_liab_`i' rank
		gen note = "11. 80% limitation on carryforward of losses"
		append using camt_firms_`i'
		save camt_firms_`i', replace 
	* Which firms dropped on/off in year X:
		use temp, clear
		keep if camt_liab_`i'_3 > 0
		keep if fyear == `i'
		keep gvkey conm		
		merge 1:1 gvkey using L_`i' 
		gen xdropped_`i' = 0
		replace xdropped_`i' = 1 if _merge == 2 
		egen dropped_`i' = sum(xdropped_`i')
		gen xadded_`i' = 0 
		replace xadded_`i' = 1 if _merge == 1
		egen added_`i' = sum(xadded_`i')
		gen note = "11. 80% limitation on carryforward of losses"
		duplicates drop note, force 
		keep note added_`i' dropped_`i' 
		merge 1:1 note using camt_est 
		drop _merge 
		save camt_est, replace 
	* Track which companies drop on/off:
		use temp, clear
		keep if camt_liab_`i'_3 > 0 & fyear == `i'
		keep gvkey conm 
		duplicates drop gvkey, force 
		save L_`i', replace 
	} 	
* Disregard losses for purposes of applicable corporation status
	use temp, clear 
	foreach i in ni pi txs dp tax_dep gross_up_dta spectrum {
		replace `i' = 0 if missing(`i')
	}
	* Calculate annual AFSI
	replace afsi = pi - txs + dp - tax_dep + gross_up_dta - spectrum - ins_gain
	drop L_* afsi_* tax_paid* tent_camt_* xcamt_* camt_*  loss_limit l_* loss_bank
	gen loss_limit = -1 * (.8 * afsi ) if afsi > 0
	gen loss_bank = 0 
	
	xtset gvkeyid fyear
	forvalues i = 2013/2022 {
		gen L_`i' = L.afsi if L.afsi < 0 & fyear == `i'
		replace L_`i' = 0 if missing(L_`i')
		replace L_`i' = L_`i' + L.loss_bank if L.loss_bank != .
		gen l_limit_`i' = 0
		replace l_limit_`i' = 1 if loss_limit > L_`i' & fyear == `i' & afsi > 0
		replace afsi = afsi + L_`i' if fyear == `i' & l_limit_`i' == 0 
		* Apply 80% limitation on loss carryforward:
			replace afsi = afsi * .2 if fyear == `i' & l_limit_`i' == 1 & afsi > 0 
			replace L_`i' = L_`i' - loss_limit if fyear == `i' & l_limit_`i' == 1
			replace loss_bank = L_`i' if fyear == `i' & l_limit_`i' == 1
	}
	
	forvalues i = 2013/2022 {
		gen afsi_`i'_3 = afsi if fyear == `i'
		replace afsi_`i'_3 = 0 if missing(afsi_`i'_3)
		replace afsi_`i'_3 = 0 if afsi_`i'_3 < 0 
		* Calculate annual ordinary corporate tax
		gen tax_paid_`i'_3 = fed_tax if fyear == `i' 
		replace tax_paid_`i'_3 = 0 if tax_paid_`i'_3 < 0
		* Calculate tentative minimum tax by multiplying AFSI by 15%
		gen tent_camt_`i'_3 = afsi_`i'_3 * .15 
		* CAMT is the difference between CAMT and ordinary corporate tax
		gen xcamt_liab_`i'_3 = tent_camt_`i'_3 - tax_paid_`i'_3
		* If CAMT is less than zero, meaning federal tax exceeds tent. CAMT,
		* replace with zero
		replace xcamt_liab_`i'_3 = 0 if xcamt_liab_`i'_3 < 0
		replace xcamt_liab_`i'_3 = 0 if fyear != `i'
		egen camt_liab_`i'_3 = sum(xcamt_liab_`i'_3),by(gvkey)
		* Replace CAMT with zero if it is a non-US or non-C corp.
		replace camt_liab_`i'_3 = 0 if drop_`i' >0
	}	
	
	forvalues i = 2013/2022 {
		* If avg. AFSI does not exceed $1B, replace with zero
		* Note this step is ignored in this version and only matters for scenario 2
		replace camt_liab_`i'_3 = 0 if app_corp_`i' == 0 
	}	
	
	save temp, replace

	* Calculate stats for this:
		* This calculates the number of firms with CAMT liability in each year,
		* the average ETR for each firm with CAMT liability in that year 
		* and the average cash tax ETR for each firm with CAMT liability 
		* in that year.	
	forvalues i = 2013/2022 {
		gen x_`i' = 0
		replace x_`i' = 1 if camt_liab_`i'_3 > 0 & fyear == `i'
		egen n_`i' = sum(x_`i')
		gen x_etr_`i' = etr if fyear == `i' & camt_liab_`i'_3 > 0
		gen x_cash_etr_`i' = cash_etr if fyear == `i' & camt_liab_`i'_3 > 0
		egen etr_`i' = mean(x_etr_`i')
		egen cash_etr_`i' = mean(x_cash_etr_`i')
	}
		* This calculates aggregate CAMT liability in each year and the number 
		* of firms that are in-scope	
		duplicates drop gvkey, force 
	forvalues i = 2013/2022 {
		egen total_camt_`i'_3 = sum(camt_liab_`i'_3)
		rename total_camt_`i'_3 camt_`i'
	}
		gen note = "12. Disregard adjustment for losses for determining app. corp status"
		keep note camt_* n_* etr_* cash_etr_*
		duplicates drop note, force 
		append using camt_est 
		sort note
		save camt_est, replace 
	* Find the firms which expect to pay the most & which firms drop on/off:
		* For 2022 and the reason why:
		use temp, clear
		keep if fyear == 2022 
		keep if camt_liab_2022_3 > 0 
		keep gvkey conm 
		merge 1:1 gvkey using L_2022 
		gen dropped = 1 if _merge == 2 
		gen added = 1 if _merge == 1 
		gen kept = 1 if _merge == 3
		foreach i in dropped added kept {
			replace `i' = 0 if missing(`i')
		}
		gen note = "12. Disregard adjustment for losses for determining app. corp status"
		drop _merge 
		append using CAMT_2022 
		save CAMT_2022, replace
	forvalues i = 2013/2022 {
		* Which firms paid the most in year X (not used in paper)
		use temp, clear
		duplicates drop gvkey, force
		gsort -camt_liab_`i'_3
		rename camt_liab_`i'_3 camt_liab_`i'
		gen rank = _n 
		keep if rank < 31
		keep conm camt_liab_`i' rank
		gen note = "12. Disregard adjustment for losses for determining app. corp status"
		append using camt_firms_`i'
		save camt_firms_`i', replace 
	* Which firms dropped on/off in year X:
		use temp, clear
		keep if camt_liab_`i'_3 > 0
		keep if fyear == `i'
		keep gvkey conm		
		merge 1:1 gvkey using L_`i' 
		gen xdropped_`i' = 0
		replace xdropped_`i' = 1 if _merge == 2 
		egen dropped_`i' = sum(xdropped_`i')
		gen xadded_`i' = 0 
		replace xadded_`i' = 1 if _merge == 1
		egen added_`i' = sum(xadded_`i')
		gen note = "12. Disregard adjustment for losses for determining app. corp status"
		duplicates drop note, force 
		keep note added_`i' dropped_`i' 
		merge 1:1 note using camt_est 
		drop _merge 
		save camt_est, replace 
	* Track which companies drop on/off:
		use temp, clear
		keep if camt_liab_`i'_3 > 0 & fyear == `i'
		keep gvkey conm 
		duplicates drop gvkey, force 
		save L_`i', replace 
	} 		

* General business credits			
	use temp, clear 
	
* Estimate general business credits based on Hoopes and Kindt:
	replace credit_pct = abs(credit_pct)
	* Calculate the dollar value of impact of credits by multiplying by 
	* pretax income.
	gen etrcredits_pct = credit_pct * pi 
		replace etrcredits_pct = 0 if pi < 0
		replace etrcredits = etrcredits*-1 if etrcredits < 0
		replace etrcredits = 0 if missing(etrcredits)
		replace etrcredits_pct = 0 if missing(etrcredits_pct)
	* Note: firms report general business credits using either pct, dollar 
	* value, or both.
	gen credit = max(etrcredits, etrcredits_pct)
	
	* Calculate annual AFSI	
	replace afsi = pi - txs + dp - tax_dep + gross_up_dta - spectrum - ins_gain
	drop L_* afsi_* tax_paid* tent_camt_* xcamt_* camt_*   loss_limit l_* loss_bank
	gen loss_limit = -1 * (.8 * afsi ) if afsi > 0
	gen loss_bank = 0 
	
	xtset gvkeyid fyear
	forvalues i = 2013/2022 {
		gen L_`i' = L.afsi if L.afsi < 0 & fyear == `i'
		replace L_`i' = 0 if missing(L_`i')
		replace L_`i' = L_`i' + L.loss_bank if L.loss_bank != .
		gen l_limit_`i' = 0
		replace l_limit_`i' = 1 if loss_limit > L_`i' & fyear == `i' & afsi > 0
		replace afsi = afsi + L_`i' if fyear == `i' & l_limit_`i' == 0 
		* Apply 80% limitation on loss carryforward:
			replace afsi = afsi * .2 if fyear == `i' & l_limit_`i' == 1 & afsi > 0 
			replace L_`i' = L_`i' - loss_limit if fyear == `i' & l_limit_`i' == 1
			replace loss_bank = L_`i' if fyear == `i' & l_limit_`i' == 1
	}
	
	forvalues i = 2013/2022 {
		gen afsi_`i'_3 = afsi if fyear == `i'
		replace afsi_`i'_3 = 0 if missing(afsi_`i'_3)
		replace afsi_`i'_3 = 0 if afsi_`i'_3 < 0 
		* Calculate annual ordinary corporate tax
		gen tax_paid_`i'_3 = fed_tax + credit if fyear == `i' 
		replace tax_paid_`i'_3 = 0 if tax_paid_`i'_3 < 0
		* Calculate tentative minimum tax by multiplying AFSI by 15%
		gen tent_camt_`i'_3 = afsi_`i'_3 * .15 
		* CAMT is the difference between CAMT and ordinary corporate tax
		gen xcamt_liab_`i'_3 = tent_camt_`i'_3 - tax_paid_`i'_3
		* If CAMT is less than zero, meaning federal tax exceeds tent. CAMT,
		* replace with zero
		replace xcamt_liab_`i'_3 = 0 if xcamt_liab_`i'_3 < 0
		replace xcamt_liab_`i'_3 = 0 if fyear != `i'
		egen camt_liab_`i'_3 = sum(xcamt_liab_`i'_3),by(gvkey)
		* Replace CAMT with zero if it is a non-US or non-C corp.		
		replace camt_liab_`i'_3 = 0 if drop_`i' >0
	}	
	
	forvalues i = 2013/2022 {
		* If avg. AFSI does not exceed $1B, replace with zero
		replace camt_liab_`i'_3 = 0 if app_corp_`i' == 0 
	}	
	save temp, replace
	
	* Calculate stats for this:
		* This calculates the number of firms with CAMT liability in each year,
		* the average ETR for each firm with CAMT liability in that year 
		* and the average cash tax ETR for each firm with CAMT liability 
		* in that year.	
	forvalues i = 2013/2022 {
		gen x_`i' = 0
		replace x_`i' = 1 if camt_liab_`i'_3 > 0 & fyear == `i'
		egen n_`i' = sum(x_`i')
		gen x_etr_`i' = etr if fyear == `i' & camt_liab_`i'_3 > 0
		gen x_cash_etr_`i' = cash_etr if fyear == `i' & camt_liab_`i'_3 > 0
		egen etr_`i' = mean(x_etr_`i')
		egen cash_etr_`i' = mean(x_cash_etr_`i')
	}
		* This calculates aggregate CAMT liability in each year and the number 
		* of firms that are in-scope	
		duplicates drop gvkey, force 
	forvalues i = 2013/2022 {
		egen total_camt_`i'_3 = sum(camt_liab_`i'_3)
		rename total_camt_`i'_3 camt_`i'
	}
		gen note = "13. Allowance for general business credits"
		keep note camt_* n_* etr_* cash_etr_*
		duplicates drop note, force 
		append using camt_est 
		sort note
		save camt_est, replace 
	* Find the firms which expect to pay the most & which firms drop on/off:
		* For 2022 and the reason why:
		use temp, clear
		keep if fyear == 2022 
		keep if camt_liab_2022_3 > 0 
		keep gvkey conm 
		merge 1:1 gvkey using L_2022 
		gen dropped = 1 if _merge == 2 
		gen added = 1 if _merge == 1 
		gen kept = 1 if _merge == 3
		foreach i in dropped added kept {
			replace `i' = 0 if missing(`i')
		}
		gen note = "13. Allowance for general business credits"
		drop _merge 
		append using CAMT_2022 
		save CAMT_2022, replace
	forvalues i = 2013/2022 {
		* Which firms paid the most in year X (not used in paper)
		use temp, clear
		duplicates drop gvkey, force
		gsort -camt_liab_`i'_3
		rename camt_liab_`i'_3 camt_liab_`i'
		gen rank = _n 
		keep if rank < 31
		keep conm camt_liab_`i' rank
		gen note = "13. Allowance for general business credits"
		append using camt_firms_`i'
		save camt_firms_`i', replace 
	* Which firms dropped on/off in year X:
		use temp, clear
		keep if camt_liab_`i'_3 > 0
		keep if fyear == `i'
		keep gvkey conm		
		merge 1:1 gvkey using L_`i' 
		gen xdropped_`i' = 0
		replace xdropped_`i' = 1 if _merge == 2 
		egen dropped_`i' = sum(xdropped_`i')
		gen xadded_`i' = 0 
		replace xadded_`i' = 1 if _merge == 1
		egen added_`i' = sum(xadded_`i')
		gen note = "13. Allowance for general business credits"
		duplicates drop note, force 
		keep note added_`i' dropped_`i' 
		merge 1:1 note using camt_est 
		drop _merge 
		save camt_est, replace 
	* Track which companies drop on/off:
		use temp, clear
		keep if camt_liab_`i'_3 > 0 & fyear == `i'
		keep gvkey conm 
		duplicates drop gvkey, force 
		save L_`i', replace 
	} 
* General business credits limited to 75% of net income			
	use temp, clear 
	drop etrcredits_pct credit 
	
	* Please refer to prior section for an explanation
		replace credit_pct = abs(credit_pct)
		gen etrcredits_pct = credit_pct * pi 
		replace etrcredits_pct = 0 if pi < 0
		replace etrcredits = etrcredits*-1 if etrcredits < 0
		replace etrcredits = 0 if missing(etrcredits)
		replace etrcredits_pct = 0 if missing(etrcredits_pct)
	gen credit = max(etrcredits, etrcredits_pct)
	
	replace afsi = pi - txs + dp - tax_dep + gross_up_dta - spectrum - ins_gain
	* We now apply the limitation on general business credits:
	gen afsi_gbc = afsi 
		replace afsi_gbc = 0 if afsi_gbc < 0 
	gen gbc_limitation = .75 * (txfed + txdfed + afsi_gbc*.15) 
		replace gbc_limitation = .75 * (afsi_gbc*.15 + txfed) if missing(gbc_limitation) & missing(txdfed)
		replace gbc_limitation = .75 * (afsi_gbc*.15 + txdfed) if missing(gbc_limitation) & missing(txfed)
		replace gbc_limitation = .75 * (afsi_gbc*.15) if missing(gbc_limitation) & missing(txfed) & missing(txdfed)
		replace gbc_limitation = 0 if gbc_limitation < 0 
	* The credit is the lesser of the limit and the credit amount
	gen credit_limited = min(gbc_limitation, credit)
	
	* Calculate annual AFSI
	replace afsi = pi - txs + dp - tax_dep + gross_up_dta - spectrum 
	drop L_* afsi_* tax_paid* tent_camt_* xcamt_* camt_*   loss_limit l_* loss_bank
	gen loss_limit = -1* (.8 * afsi ) if afsi > 0
	gen loss_bank = 0 
	
	xtset gvkeyid fyear
	forvalues i = 2013/2022 {
		gen L_`i' = L.afsi if L.afsi < 0 & fyear == `i'
		replace L_`i' = 0 if missing(L_`i')
		replace L_`i' = L_`i' + L.loss_bank if L.loss_bank != .
		gen l_limit_`i' = 0
		replace l_limit_`i' = 1 if loss_limit > L_`i' & fyear == `i' & afsi > 0
		replace afsi = afsi + L_`i' if fyear == `i' & l_limit_`i' == 0 
		* Apply 80% limitation on loss carryforward:
			replace afsi = afsi * .2 if fyear == `i' & l_limit_`i' == 1 & afsi > 0 
			replace L_`i' = L_`i' - loss_limit if fyear == `i' & l_limit_`i' == 1
			replace loss_bank = L_`i' if fyear == `i' & l_limit_`i' == 1
	}
	
	forvalues i = 2013/2022 {
		gen afsi_`i'_3 = afsi if fyear == `i'
		replace afsi_`i'_3 = 0 if missing(afsi_`i'_3)
		replace afsi_`i'_3 = 0 if afsi_`i'_3 < 0 
		* Calculate annual ordinary corporate tax
		gen tax_paid_`i'_3 = fed_tax + credit_limited if fyear == `i' 
		replace tax_paid_`i'_3 = 0 if tax_paid_`i'_3 < 0
		* Calculate tentative minimum tax by multiplying AFSI by 15%
		gen tent_camt_`i'_3 = afsi_`i'_3 * .15 
		* CAMT is the difference between CAMT and ordinary corporate tax
		gen xcamt_liab_`i'_3 = tent_camt_`i'_3 - tax_paid_`i'_3
		* If CAMT is less than zero, meaning federal tax exceeds tent. CAMT,
		* replace with zero
		replace xcamt_liab_`i'_3 = 0 if xcamt_liab_`i'_3 < 0
		replace xcamt_liab_`i'_3 = 0 if fyear != `i'
		egen camt_liab_`i'_3 = sum(xcamt_liab_`i'_3),by(gvkey)
		* Replace CAMT with zero if it is a non-US or non-C corp.
		replace camt_liab_`i'_3 = 0 if drop_`i' >0
	}	
	
	forvalues i = 2013/2022 {
		* If avg. AFSI does not exceed $1B, replace with zero
		replace camt_liab_`i'_3 = 0 if app_corp_`i' == 0 
	}	

	save temp, replace
	* Calculate stats for this:
		* This calculates the number of firms with CAMT liability in each year,
		* the average ETR for each firm with CAMT liability in that year 
		* and the average cash tax ETR for each firm with CAMT liability 
		* in that year.	
	forvalues i = 2013/2022 {
		gen x_`i' = 0
		replace x_`i' = 1 if camt_liab_`i'_3 > 0 & fyear == `i'
		egen n_`i' = sum(x_`i')
		gen x_etr_`i' = etr if fyear == `i' & camt_liab_`i'_3 > 0
		gen x_cash_etr_`i' = cash_etr if fyear == `i' & camt_liab_`i'_3 > 0
		egen etr_`i' = mean(x_etr_`i')
		egen cash_etr_`i' = mean(x_cash_etr_`i')
	}
		* This calculates aggregate CAMT liability in each year and the number 
		* of firms that are in-scope	
		duplicates drop gvkey, force 
	forvalues i = 2013/2022 {
		egen total_camt_`i'_3 = sum(camt_liab_`i'_3)
		rename total_camt_`i'_3 camt_`i'
	}
		gen note = "14. Limitation on allowance for general business credits"
		keep note camt_* n_* etr_* cash_etr_*
		duplicates drop note, force 
		append using camt_est 
		sort note
		save camt_est, replace 
	* Find the firms which expect to pay the most & which firms drop on/off:
		* For 2022 and the reason why:
		use temp, clear
		keep if fyear == 2022 
		keep if camt_liab_2022_3 > 0 
		keep gvkey conm 
		merge 1:1 gvkey using L_2022 
		gen dropped = 1 if _merge == 2 
		gen added = 1 if _merge == 1 
		gen kept = 1 if _merge == 3
		foreach i in dropped added kept {
			replace `i' = 0 if missing(`i')
		}
		gen note = "14. Limitation on allowance for general business credits"
		drop _merge 
		append using CAMT_2022 
		save CAMT_2022, replace
	forvalues i = 2013/2022 {
		* Which firms paid the most in year X (not used in paper)
		use temp, clear
		duplicates drop gvkey, force
		gsort -camt_liab_`i'_3
		rename camt_liab_`i'_3 camt_liab_`i'
		gen rank = _n 
		keep if rank < 31
		keep conm camt_liab_`i' rank
		gen note = "14. Limitation on allowance for general business credits"
		append using camt_firms_`i'
		save camt_firms_`i', replace 
	* Which firms dropped on/off in year X:
		use temp, clear
		keep if camt_liab_`i'_3 > 0
		keep if fyear == `i'
		keep gvkey conm		
		merge 1:1 gvkey using L_`i' 
		gen xdropped_`i' = 0
		replace xdropped_`i' = 1 if _merge == 2 
		egen dropped_`i' = sum(xdropped_`i')
		gen xadded_`i' = 0 
		replace xadded_`i' = 1 if _merge == 1
		egen added_`i' = sum(xadded_`i')
		gen note = "14. Limitation on allowance for general business credits"
		duplicates drop note, force 
		keep note added_`i' dropped_`i' 
		merge 1:1 note using camt_est 
		drop _merge 
		save camt_est, replace 		
	* Track which companies drop on/off:
		use temp, clear
		keep if camt_liab_`i'_3 > 0 & fyear == `i'
		keep gvkey conm 
		duplicates drop gvkey, force 
		save L_`i', replace 
	} 	
* The firm is an applicable corporation forever:
	use temp, clear 
	drop etrcredits_pct credit gbc_limitation credit_limited
	
	* See prior section (general business credits) for an explanation:
		replace credit_pct = abs(credit_pct)
		gen etrcredits_pct = credit_pct * pi 
		replace etrcredits_pct = 0 if pi < 0
		replace etrcredits = etrcredits*-1 if etrcredits < 0
		replace etrcredits = 0 if missing(etrcredits)
		replace etrcredits_pct = 0 if missing(etrcredits_pct)
	gen credit = max(etrcredits, etrcredits_pct)
	
	replace afsi = pi - txs + dp - tax_dep + gross_up_dta - spectrum - ins_gain
	* See prior section (limitation on GBC) for explanation:
	gen afsi_gbc = afsi 
		replace afsi_gbc = 0 if afsi_gbc < 0 
	gen gbc_limitation = .75 * (txfed + txdfed + afsi_gbc*.15) 
		replace gbc_limitation = .75 * (afsi_gbc*.15 + txfed) if missing(gbc_limitation) & missing(txdfed)
		replace gbc_limitation = .75 * (afsi_gbc*.15 + txdfed) if missing(gbc_limitation) & missing(txfed)
		replace gbc_limitation = .75 * (afsi_gbc*.15) if missing(gbc_limitation) & missing(txfed) & missing(txdfed)
		replace gbc_limitation = 0 if gbc_limitation < 0 
	gen credit_limited = min(gbc_limitation, credit)
	* Calculate annual AFSI
	replace afsi = pi - txs + dp - tax_dep + gross_up_dta - spectrum - ins_gain
	drop L_* afsi_* tax_paid* tent_camt_* xcamt_* camt_*  loss_limit l_* loss_bank
	gen loss_limit = -1* (.8 * afsi ) if afsi > 0
	gen loss_bank = 0 
	
	xtset gvkeyid fyear
	forvalues i = 2013/2022 {
		gen L_`i' = L.afsi if L.afsi < 0 & fyear == `i'
		replace L_`i' = 0 if missing(L_`i')
		replace L_`i' = L_`i' + L.loss_bank if L.loss_bank != .
		gen l_limit_`i' = 0
		replace l_limit_`i' = 1 if loss_limit > L_`i' & fyear == `i' & afsi > 0
		replace afsi = afsi + L_`i' if fyear == `i' & l_limit_`i' == 0 
		* Apply 80% limitation on loss carryforward:
			replace afsi = afsi * .2 if fyear == `i' & l_limit_`i' == 1 & afsi > 0 
			replace L_`i' = L_`i' - loss_limit if fyear == `i' & l_limit_`i' == 1
			replace loss_bank = L_`i' if fyear == `i' & l_limit_`i' == 1
	}
	forvalues i = 2013/2022 {
		gen afsi_`i'_3 = afsi if fyear == `i'
		replace afsi_`i'_3 = 0 if missing(afsi_`i'_3)
		replace afsi_`i'_3 = 0 if afsi_`i'_3 < 0 
		* Calculate annual ordinary corporate tax
		gen tax_paid_`i'_3 = fed_tax + credit_limited if fyear == `i' 
		replace tax_paid_`i'_3 = 0 if tax_paid_`i'_3 < 0
		* Calculate tentative minimum tax by multiplying AFSI by 15%
		gen tent_camt_`i'_3 = afsi_`i'_3 * .15 
		* CAMT is the difference between CAMT and ordinary corporate tax
		gen xcamt_liab_`i'_3 = tent_camt_`i'_3 - tax_paid_`i'_3
		* If CAMT is less than zero, meaning federal tax exceeds tent. CAMT,
		* replace with zero
		replace xcamt_liab_`i'_3 = 0 if xcamt_liab_`i'_3 < 0
		replace xcamt_liab_`i'_3 = 0 if fyear != `i'
		egen camt_liab_`i'_3 = sum(xcamt_liab_`i'_3),by(gvkey)
		* Replace CAMT with zero if it is a non-US or non-C corp.
		replace camt_liab_`i'_3 = 0 if drop_`i' >0
	}	
	gen earliest_yr = .
	forvalues i = 2013/2022 {
		replace earliest_yr = fyear * app_corp_`i' if fyear == `i'
		replace earliest_yr = . if earliest_yr == 0 
	}	
	egen first_app_yr = min(earliest_yr),by(gvkey)
		
	forvalues i = 2013/2022 {
		* If avg. AFSI does not exceed $1B, replace with zero
		replace camt_liab_`i'_3 = 0 if app_corp_`i' == 0 	
		* Under CAMT_scenario2, you will find an additional line of code here
		* which applies the once an app. corp, always an app. corp. rule 
		* We do not want to apply this rule here because we want to estimate 
		* CAMT in 2020, 2021, 2022 without regard to the firm's earlier perform-
		* ance. 
	}
			save temp, replace
	* Calculate stats for this:
		* This calculates the number of firms with CAMT liability in each year,
		* the average ETR for each firm with CAMT liability in that year 
		* and the average cash tax ETR for each firm with CAMT liability 
		* in that year.	
	forvalues i = 2013/2022 {
		gen x_`i' = 0
		replace x_`i' = 1 if camt_liab_`i'_3 > 0 & fyear == `i'
		egen n_`i' = sum(x_`i')
		gen x_etr_`i' = etr if fyear == `i' & camt_liab_`i'_3 > 0
		gen x_cash_etr_`i' = cash_etr if fyear == `i' & camt_liab_`i'_3 > 0
		egen etr_`i' = mean(x_etr_`i')
		egen cash_etr_`i' = mean(x_cash_etr_`i')
	}
		* This calculates aggregate CAMT liability in each year and the number 
		* of firms that are in-scope	
		duplicates drop gvkey, force 
	forvalues i = 2013/2022 {
		egen total_camt_`i'_3 = sum(camt_liab_`i'_3)
		rename total_camt_`i'_3 camt_`i'
	}
		gen note = "15. Once an applicable corporation, always an applicable corporation"
		keep note camt_* n_* etr_* cash_etr_*
		duplicates drop note, force 
		append using camt_est 
		sort note
		save camt_est, replace 
	* Find the firms which expect to pay the most & which firms drop on/off:
		* For 2022 and the reason why:
		use temp, clear
		keep if fyear == 2022 
		keep if camt_liab_2022_3 > 0 
		keep gvkey conm 
		merge 1:1 gvkey using L_2022 
		gen dropped = 1 if _merge == 2 
		gen added = 1 if _merge == 1 
		gen kept = 1 if _merge == 3
		foreach i in dropped added kept {
			replace `i' = 0 if missing(`i')
		}
		gen note = "15. Once an applicable corporation, always an applicable corporation"
		drop _merge 
		append using CAMT_2022 
		save CAMT_2022, replace
	forvalues i = 2013/2022 {
		* Which firms paid the most in year X (not used in paper)
		use temp, clear
		duplicates drop gvkey, force
		gsort -camt_liab_`i'_3
		rename camt_liab_`i'_3 camt_liab_`i'
		gen rank = _n 
		keep if rank < 31
		keep conm camt_liab_`i' rank
		gen note = "15. Once an applicable corporation, always an applicable corporation"
		append using camt_firms_`i'
		save camt_firms_`i', replace 
	* Which firms dropped on/off in year X:
		use temp, clear
		keep if camt_liab_`i'_3 > 0
		keep if fyear == `i'
		keep gvkey conm		
		merge 1:1 gvkey using L_`i' 
		gen xdropped_`i' = 0
		replace xdropped_`i' = 1 if _merge == 2 
		egen dropped_`i' = sum(xdropped_`i')
		gen xadded_`i' = 0 
		replace xadded_`i' = 1 if _merge == 1
		egen added_`i' = sum(xadded_`i')
		gen note = "15. Once an applicable corporation, always an applicable corporation"
		duplicates drop note, force 
		keep note added_`i' dropped_`i' 
		merge 1:1 note using camt_est 
		drop _merge 
		save camt_est, replace 

	* Track which companies drop on/off:
		use temp, clear
		keep if camt_liab_`i'_3 > 0 & fyear == `i'
		keep gvkey conm 
		duplicates drop gvkey, force 
		save L_`i', replace 
	} 

* CAMT Foreign Tax Credit:
	use temp, clear 
	drop etrcredits_pct credit gbc_limitation credit_limited earliest_yr first_app_yr
	* See GBC section for explanation:
		replace credit_pct = abs(credit_pct)
		gen etrcredits_pct = credit_pct * pi 
		replace etrcredits_pct = 0 if pi < 0
		replace etrcredits = etrcredits*-1 if etrcredits < 0
		replace etrcredits = 0 if missing(etrcredits)
		replace etrcredits_pct = 0 if missing(etrcredits_pct)
	gen credit = max(etrcredits, etrcredits_pct)
	
	replace afsi = pi - txs + dp - tax_dep + gross_up_dta - spectrum - ins_gain
	* See GBC limit section for explanation:
	gen afsi_gbc = afsi 
		replace afsi_gbc = 0 if afsi_gbc < 0 
	gen gbc_limitation = .75 * (txfed + txdfed + afsi_gbc*.15) 
		replace gbc_limitation = .75 * (afsi_gbc*.15 + txfed) if missing(gbc_limitation) & missing(txdfed)
		replace gbc_limitation = .75 * (afsi_gbc*.15 + txdfed) if missing(gbc_limitation) & missing(txfed)
		replace gbc_limitation = .75 * (afsi_gbc*.15) if missing(gbc_limitation) & missing(txfed) & missing(txdfed)
		replace gbc_limitation = 0 if gbc_limitation < 0 
	gen credit_limited = min(gbc_limitation, credit)
	
	* Estimate foreign tax credit based on current foreign tax expense:
	gen ftc = txfo 
		replace ftc = 0 if missing(ftc)
		replace ftc = 0 if ftc < 0 
	* Calculate annual AFSI
	replace afsi = pi - txs + dp - tax_dep + gross_up_dta - spectrum - ins_gain
	drop L_* afsi_* tax_paid* tent_camt_* xcamt_* camt_*  loss_limit l_* loss_bank
	gen loss_limit = -1 * (.8 * afsi ) if afsi > 0
	gen loss_bank = 0 
	
	xtset gvkeyid fyear
	forvalues i = 2013/2022 {
		gen L_`i' = L.afsi if L.afsi < 0 & fyear == `i'
		replace L_`i' = 0 if missing(L_`i')
		replace L_`i' = L_`i' + L.loss_bank if L.loss_bank != .
		gen l_limit_`i' = 0
		replace l_limit_`i' = 1 if loss_limit > L_`i' & fyear == `i' & afsi > 0
		replace afsi = afsi + L_`i' if fyear == `i' & l_limit_`i' == 0 
		* Apply 80% limitation on loss carryforward:
			replace afsi = afsi * .2 if fyear == `i' & l_limit_`i' == 1 & afsi > 0 
			replace L_`i' = L_`i' - loss_limit if fyear == `i' & l_limit_`i' == 1
			replace loss_bank = L_`i' if fyear == `i' & l_limit_`i' == 1
	}
	forvalues i = 2013/2022 {
		gen afsi_`i'_3 = afsi if fyear == `i'
		replace afsi_`i'_3 = 0 if missing(afsi_`i'_3)
		replace afsi_`i'_3 = 0 if afsi_`i'_3 < 0 
		* Calculate annual ordinary corporate tax - incorporate GBC and FTC
		gen tax_paid_`i'_3 = fed_tax + credit_limited +ftc if fyear == `i' 
		replace tax_paid_`i'_3 = 0 if tax_paid_`i'_3 < 0
		* Calculate tentative minimum tax by multiplying AFSI by 15%
		gen tent_camt_`i'_3 = afsi_`i'_3 * .15 
		* CAMT is the difference between CAMT and ordinary corporate tax
		gen xcamt_liab_`i'_3 = tent_camt_`i'_3 - tax_paid_`i'_3
		* If CAMT is less than zero, meaning federal tax exceeds tent. CAMT,
		* replace with zero
		replace xcamt_liab_`i'_3 = 0 if xcamt_liab_`i'_3 < 0
		replace xcamt_liab_`i'_3 = 0 if fyear != `i'
		egen camt_liab_`i'_3 = sum(xcamt_liab_`i'_3),by(gvkey)
		* Replace CAMT with zero if it is a non-US or non-C corp.	
		replace camt_liab_`i'_3 = 0 if drop_`i' >0
	}	
	gen earliest_yr = .
	forvalues i = 2013/2022 {
		replace earliest_yr = fyear * app_corp_`i' if fyear == `i'
		replace earliest_yr = . if earliest_yr == 0 
	}	
	egen first_app_yr = min(earliest_yr),by(gvkey)
		
	forvalues i = 2013/2022 {
		* If avg. AFSI does not exceed $1B, replace with zero
		replace camt_liab_`i'_3 = 0 if app_corp_`i' == 0 		
	}
			save temp, replace	
			
	* Calculate stats for this:
		* This calculates the number of firms with CAMT liability in each year,
		* the average ETR for each firm with CAMT liability in that year 
		* and the average cash tax ETR for each firm with CAMT liability 
		* in that year.	
	forvalues i = 2013/2022 {
		gen x_`i' = 0
		replace x_`i' = 1 if camt_liab_`i'_3 > 0 & fyear == `i'
		egen n_`i' = sum(x_`i')
		gen x_etr_`i' = etr if fyear == `i' & camt_liab_`i'_3 > 0
		gen x_cash_etr_`i' = cash_etr if fyear == `i' & camt_liab_`i'_3 > 0
		egen etr_`i' = mean(x_etr_`i')
		egen cash_etr_`i' = mean(x_cash_etr_`i')
	}
		* This calculates aggregate CAMT liability in each year and the number 
		* of firms that are in-scope	
		duplicates drop gvkey, force 
	forvalues i = 2013/2022 {
		egen total_camt_`i'_3 = sum(camt_liab_`i'_3)
		rename total_camt_`i'_3 camt_`i'
	}
		gen note = "16. CAMT Foreign Tax Credit"
		keep note camt_* n_* etr_* cash_etr_*
		duplicates drop note, force 
		append using camt_est 
		sort note
		save camt_est, replace 
	* Find the firms which expect to pay the most & which firms drop on/off:
		* For 2022 and the reason why:
		use temp, clear
		keep if fyear == 2022 
		keep if camt_liab_2022_3 > 0 
		keep gvkey conm 
		merge 1:1 gvkey using L_2022 
		gen dropped = 1 if _merge == 2 
		gen added = 1 if _merge == 1 
		gen kept = 1 if _merge == 3
		foreach i in dropped added kept {
			replace `i' = 0 if missing(`i')
		}
		gen note = "16. CAMT Foreign Tax Credit"
		drop _merge 
		append using CAMT_2022 
		save CAMT_2022, replace
	forvalues i = 2013/2022 {
		* Which firms paid the most in year X (not used in paper)
		use temp, clear
		duplicates drop gvkey, force
		gsort -camt_liab_`i'_3
		rename camt_liab_`i'_3 camt_liab_`i'
		gen rank = _n 
		keep if rank < 31
		keep conm camt_liab_`i' rank
		gen note = "16. CAMT Foreign Tax Credit"
		append using camt_firms_`i'
		save camt_firms_`i', replace 
	* Which firms dropped on/off in year X:
		use temp, clear
		keep if camt_liab_`i'_3 > 0
		keep if fyear == `i'
		keep gvkey conm		
		merge 1:1 gvkey using L_`i' 
		gen xdropped_`i' = 0
		replace xdropped_`i' = 1 if _merge == 2 
		egen dropped_`i' = sum(xdropped_`i')
		gen xadded_`i' = 0 
		replace xadded_`i' = 1 if _merge == 1
		egen added_`i' = sum(xadded_`i')
		gen note = "16. CAMT Foreign Tax Credit"
		duplicates drop note, force 
		keep note added_`i' dropped_`i' 
		merge 1:1 note using camt_est 
		drop _merge 
		save camt_est, replace 

	* Track which companies drop on/off:
		use temp, clear
		keep if camt_liab_`i'_3 > 0 & fyear == `i'
		keep gvkey conm 
		duplicates drop gvkey, force 
		save L_`i', replace 
	} 

* CAMT Foreign Tax Credit Limited to 15% of AFSI:
	use temp, clear 
	drop etrcredits_pct credit gbc_limitation credit_limited earliest_yr first_app_yr ftc 
	* See GBC section for explanation:
		replace credit_pct = abs(credit_pct)
		gen etrcredits_pct = credit_pct * pi 
		replace etrcredits_pct = 0 if pi < 0
		replace etrcredits = etrcredits*-1 if etrcredits < 0
		replace etrcredits = 0 if missing(etrcredits)
		replace etrcredits_pct = 0 if missing(etrcredits_pct)
	gen credit = max(etrcredits, etrcredits_pct)
	
	replace afsi = pi - txs + dp - tax_dep + gross_up_dta - spectrum 	- ins_gain
	* See GBC Limit section for explanation:
	gen afsi_gbc = afsi 
		replace afsi_gbc = 0 if afsi_gbc < 0 
	gen gbc_limitation = .75 * (txfed + txdfed + afsi_gbc*.15) 
		replace gbc_limitation = .75 * (afsi_gbc*.15 + txfed) if missing(gbc_limitation) & missing(txdfed)
		replace gbc_limitation = .75 * (afsi_gbc*.15 + txdfed) if missing(gbc_limitation) & missing(txfed)
		replace gbc_limitation = .75 * (afsi_gbc*.15) if missing(gbc_limitation) & missing(txfed) & missing(txdfed)
		replace gbc_limitation = 0 if gbc_limitation < 0 
	gen credit_limited = min(gbc_limitation, credit)
	* See FTC section for explanation:
	gen ftc = txfo 
		replace ftc = 0 if missing(ftc)
		replace ftc = 0 if ftc < 0 
	* Calculate annual AFSI	
	replace afsi = pi - txs + dp - tax_dep + gross_up_dta - spectrum - ins_gain
	drop L_* afsi_* tax_paid* tent_camt_* xcamt_* camt_* loss_limit l_* loss_bank
	gen loss_limit = -1 * (.8 * afsi ) if afsi > 0
	gen loss_bank = 0 
	
	xtset gvkeyid fyear
	forvalues i = 2013/2022 {
		gen L_`i' = L.afsi if L.afsi < 0 & fyear == `i'
		replace L_`i' = 0 if missing(L_`i')
		replace L_`i' = L_`i' + L.loss_bank if L.loss_bank != .
		gen l_limit_`i' = 0
		replace l_limit_`i' = 1 if loss_limit > L_`i' & fyear == `i' & afsi > 0
		replace afsi = afsi + L_`i' if fyear == `i' & l_limit_`i' == 0 
		* Apply 80% limitation on loss carryforward:
			replace afsi = afsi * .2 if fyear == `i' & l_limit_`i' == 1 & afsi > 0 
			replace L_`i' = L_`i' - loss_limit if fyear == `i' & l_limit_`i' == 1
			replace loss_bank = L_`i' if fyear == `i' & l_limit_`i' == 1
	}

	forvalues i = 2013/2022 {
		gen afsi_`i'_3 = afsi if fyear == `i'
		replace afsi_`i'_3 = 0 if missing(afsi_`i'_3)
		replace afsi_`i'_3 = 0 if afsi_`i'_3 < 0 
		* Calculate FTC Limitation based on pretax foreign income:
		gen pifo_`i' = pifo if fyear == `i'
		replace pifo_`i' = 0 if missing(pifo_`i')
		replace pifo_`i' = 0 if pifo_`i' < 0 
		gen ftc_limit_`i' = 0 
		replace ftc_limit_`i' = .15 * pifo_`i' if pifo_`i' != .
		replace ftc_limit_`i' = 0 if missing(ftc_limit_`i')
		* The FTC will be the minimum of the firms FTC and the limitation on FTC 
		gen ftc_`i' = min(ftc_limit_`i', ftc)
		* Calculate annual ordinary corporate tax
		gen tax_paid_`i'_3 = fed_tax + credit_limited +ftc_`i' if fyear == `i' 
		replace tax_paid_`i'_3 = 0 if tax_paid_`i'_3 < 0
		* Calculate tentative minimum tax by multiplying AFSI by 15%
		gen tent_camt_`i'_3 = afsi_`i'_3 * .15 
		* CAMT is the difference between CAMT and ordinary corporate tax
		gen xcamt_liab_`i'_3 = tent_camt_`i'_3 - tax_paid_`i'_3
		* If CAMT is less than zero, meaning federal tax exceeds tent. CAMT,
		* replace with zero
		replace xcamt_liab_`i'_3 = 0 if xcamt_liab_`i'_3 < 0
		replace xcamt_liab_`i'_3 = 0 if fyear != `i'
		egen camt_liab_`i'_3 = sum(xcamt_liab_`i'_3),by(gvkey)
		* Replace CAMT with zero if it is a non-US or non-C corp.
		replace camt_liab_`i'_3 = 0 if drop_`i' >0
	}	
	gen earliest_yr = .
	forvalues i = 2013/2022 {
		replace earliest_yr = fyear * app_corp_`i' if fyear == `i'
		replace earliest_yr = . if earliest_yr == 0 
	}	
	egen first_app_yr = min(earliest_yr),by(gvkey)
		
	forvalues i = 2013/2022 {
		* If avg. AFSI does not exceed $1B, replace with zero
		replace camt_liab_`i'_3 = 0 if app_corp_`i' == 0 		
	}
			save temp, replace	
	* Calculate stats for this:
		* This calculates the number of firms with CAMT liability in each year,
		* the average ETR for each firm with CAMT liability in that year 
		* and the average cash tax ETR for each firm with CAMT liability 
		* in that year.	
	forvalues i = 2013/2022 {
		gen x_`i' = 0
		replace x_`i' = 1 if camt_liab_`i'_3 > 0 & fyear == `i'
		egen n_`i' = sum(x_`i')
		gen x_etr_`i' = etr if fyear == `i' & camt_liab_`i'_3> 0
		gen x_cash_etr_`i' = cash_etr if fyear == `i' & camt_liab_`i'_3 > 0
		egen etr_`i' = mean(x_etr_`i')
		egen cash_etr_`i' = mean(x_cash_etr_`i')
	}
		* This calculates aggregate CAMT liability in each year and the number 
		* of firms that are in-scope	
		duplicates drop gvkey, force 
	forvalues i = 2013/2022 {
		egen total_camt_`i'_3 = sum(camt_liab_`i'_3)
		rename total_camt_`i'_3 camt_`i'
	}
		gen note = "17. CAMT Foreign Tax Credit limited to 15% of foreign-source AFSI"
		keep note camt_* n_* etr_* cash_etr_*
		duplicates drop note, force 
		append using camt_est 
		sort note
		save camt_est, replace 
	* Find the firms which expect to pay the most & which firms drop on/off:
		* For 2022 and the reason why:
		use temp, clear
		keep if fyear == 2022 
		keep if camt_liab_2022_3 > 0 
		keep gvkey conm 
		merge 1:1 gvkey using L_2022 
		gen dropped = 1 if _merge == 2 
		gen added = 1 if _merge == 1 
		gen kept = 1 if _merge == 3
		foreach i in dropped added kept {
			replace `i' = 0 if missing(`i')
		}
		gen note = "17. CAMT Foreign Tax Credit limited to 15% of foreign-source AFSI"
		drop _merge 
		append using CAMT_2022 
		save CAMT_2022, replace
	forvalues i = 2013/2022 {
		* Which firms paid the most in year X (not used in paper)
		use temp, clear
		duplicates drop gvkey, force
		gsort -camt_liab_`i'_3
		rename camt_liab_`i'_3 camt_liab_`i'
		gen rank = _n 
		keep if rank < 31
		keep conm camt_liab_`i' rank
		gen note = "17. CAMT Foreign Tax Credit limited to 15% of foreign-source AFSI"
		append using camt_firms_`i'
		save camt_firms_`i', replace 
	* Which firms dropped on/off in year X:
		use temp, clear
		keep if camt_liab_`i'_3 > 0
		keep if fyear == `i'
		keep gvkey conm		
		merge 1:1 gvkey using L_`i' 
		gen xdropped_`i' = 0
		replace xdropped_`i' = 1 if _merge == 2 
		egen dropped_`i' = sum(xdropped_`i')
		gen xadded_`i' = 0 
		replace xadded_`i' = 1 if _merge == 1
		egen added_`i' = sum(xadded_`i')
		gen note = "17. CAMT Foreign Tax Credit limited to 15% of foreign-source AFSI"
		duplicates drop note, force 
		keep note added_`i' dropped_`i' 
		merge 1:1 note using camt_est 
		drop _merge 
		save camt_est, replace 

	* Track which companies drop on/off:
		use temp, clear
		keep if camt_liab_`i'_3 > 0 & fyear == `i'
		keep gvkey conm 
		duplicates drop gvkey, force 
		save L_`i', replace 
	} 

* Calculate refunds of CAMT: NOTE THIS IS NOT USED IN THE PAPER. ONLY USED 
* in scenario2:

	use temp, clear 
	gen camt_ts = .	
	* Create a time series for firms' CAMT payments (This is only used for Scenario2)
	forvalues i = 2013/2022{
		replace camt_ts = camt_liab_`i'_3 if fyear == `i'
	}
	gen creditable_taxes = 0
	forvalues i = 2013/2022 {
		replace creditable_taxes = tax_paid_`i'_3 - tent_camt_`i'_3 if fyear == `i'
		replace creditable_taxes = 0 if creditable_taxes < 0  
		replace creditable_taxes = 0 if camt_liab_`i'_3 > 0 & fyear == `i'
	}
		
	replace camt_ts = 0 if missing(camt_ts)
	gen cum_camt = 0
	capture drop credit
	gen credit = 0 
	xtset gvkeyid fyear 
	sort gvkeyid fyear
	forvalues i = 2013/2022 {
		replace cum_camt = camt_ts + L.cum_camt if fyear == `i' & L.cum_camt != .
		replace credit = min(cum_camt, creditable_taxes) if fyear == `i'
		gen refund_`i' = min(cum_camt, creditable_taxes) if fyear == `i'
		replace credit = 0 if fyear == `i' & camt_liab_`i'_3 > 0 
		replace refund_`i' = 0 if fyear == `i' & camt_liab_`i'_3 > 0 
		replace refund_`i' = 0 if missing(refund_`i')
		replace cum_camt = max(cum_camt - credit,0) 
	}

	save temp, replace 

	
	use temp, clear
* Calculate stats	
	forvalues i = 2013/2022 {
		gen x_`i' = 0
		replace x_`i' = 1 if refund_`i' > 0 & fyear == `i'
		egen rn_`i' = sum(x_`i')
		gen x_etr_`i' = etr if fyear == `i' & refund_`i' > 0
		gen x_cash_etr_`i' = cash_etr if fyear == `i' & refund_`i' > 0
		egen etr_`i' = mean(x_etr_`i')
		egen cash_etr_`i' = mean(x_cash_etr_`i')
	}
	forvalues i = 2013/2022 {
		egen total_refund_`i' = sum(refund_`i')
		gen n_ref_`i' = 1 if refund_`i' > 0 & refund_`i' != . 
		replace n_ref_`i' = 0 if missing(n_ref_`i')
		egen nr_`i' = sum(n_ref_`i')
	}
	duplicates drop gvkey, force 

		gen note = "18. CAMT Refunds"
		keep note total_refund_* rn_* nr_*
		duplicates drop note, force 
		append using camt_est 	
		save camt_est, replace

* Create table 2: CAMT Est. at every step
	use camt_est, clear
	sort note 
	* These steps matter for Scenario2 but are not considered for Scenario1 
	drop if note == "15. Once an applicable corporation, always an applicable corporation"
	drop if note == "12. Disregard adjustment for losses for determining app. corp status"
	drop n_2010 n_2011 n_2012 camt_2010 camt_2011 camt_2012 	
	* This gets the results for Table 1 Panel A
	order note inscope_2020 n_2020 dropped_2020 added_2020 camt_2020 etr_2020 cash_etr_2020
	* This gets the results for Table 1 Panel B
	order note inscope_2021 n_2021 dropped_2021 added_2021 camt_2021 etr_2021 cash_etr_2021     
	* This gets the results for Table 1 Panel C
	order note inscope_2022 n_2022 dropped_2022 added_2022 camt_2022 etr_2022 cash_etr_2022

* Create table 4: Names of companies with CAMT in 2022:
	use temp, clear 
	gsort -camt_liab_2022_3 
	*Create table 4: browse conm camt_liab_2022_3 pi if camt_liab_2022_3 > 0
	keep if fyear == 2022
	duplicates drop conm, force

* Compare with Hoopes paper: (This is just a CSV file with the Hoopes table of 
* 2021 companies with CAMT liability)
	import delim "C:\Users\nborn\Dropbox (Penn)\Project-CAMT\hoopes.csv", clear varnames(1)
	gsort -liability
 	save hoopes, replace 
	use temp, clear 
	gsort -camt_liab_2021_3 
	duplicates drop conm, force
	keep conm tic camt_liab_2021_3 pi
	keep if camt_liab_2021_3 > 0 
	merge 1:1 tic using hoopes 
	gsort -camt_liab_2021_3 
	order tic conm camt_liab_2021_3
	order name liability conm camt_liab_2021_3 
	gen delta = liability - camt_liab_2021_3
	gen pct = delta/camt_liab_2021_3

* Get the unique number of firms that would have liabilities in 2020, 2021, 2022
	use temp, clear 
	keep if fyear == 2021 | fyear == 2020 | fyear == 2022
	keep if camt_liab_2020_3 > 0 | camt_liab_2021_3 > 0 | camt_liab_2022_3 > 0
	duplicates drop gvkey, force 	

* Create file that will eventually be used to match to disclosures:	
	use temp, clear			
	keep if fyear == 2021  | fyear == 2022 
	destring gvkey, replace
	save compustat_data, replace 
	
	* Create table that allows you to keep track of matches:
	keep gvkey 
	gen X = 1 
	egen count = sum(X)
	gen note = "1. Compustat firms"
	duplicates drop note, force 
	save count_data, replace 
	
	use compustat_data, clear 
	gen X1 = 1 if camt_liab_2021_3 > 0 
	gen X2 = 1 if camt_liab_2022_3 > 0 
		replace X1 = 0 if missing(X1)
		replace X2 = 0 if missing(X2)
	duplicates drop gvkey, force 
	keep gvkey X1 X2 camt_liab_2021_3 camt_liab_2022_3
	gen X = 1 
	egen count = sum(X)
	egen count_2021 = sum(X1)
	egen count_2022 = sum(X2)
	egen total_2021 = sum(camt_liab_2021_3)
	egen total_2022 = sum(camt_liab_2022_3)
	gen note = "1. Compustat firms"
	duplicates drop note, force 
	keep count note count_2021 count_2022 total_2021 total_2022 
	merge 1:1 note using count_data 
	drop _merge
	save count_data, replace 	
		
* Clean detailed databases:
	
	* 10-K database:
	capture import delim "DIRECTORY\secdata_10K_DETAIL.csv", delimiter(comma) bindquote(strict) varnames(1) maxquotedrows(unlimited) clear
	duplicates drop v1 rownum size cik fdate wrdsfname check camt_no camt_yes camt_boilerplate camt_oldamt camt_immaterial camt_drop handcheck quantitative, force 
	drop if camt_drop == 1
	
	* Because the text is based on mentions of CAMT/CAMT-related words, we need
	* to sum the type of disclosure by the firm. 
	
	foreach i in uncertain yes no drop oldamt immaterial  boilerplate{
		egen total_`i'_10k = sum(camt_`i'),by(cik)
		replace total_`i'_10k = 1 if total_`i'_10k > 0 
		drop camt_`i'
		}
		* drop_10k indicated a situation where the letters CAMT were included as part 
		* of another word and were inadvertently tagged as a CAMT disclosure
		drop if total_drop_10k == 1 & total_uncertain_10k == 0 & total_yes_10k == 0 & total_no_10k == 0  & total_oldamt_10k == 0 & total_boilerplate_10k == 0 
		* oldamt_10k is an indicator for mentions of the old AMT, which was 
		* quite commonly discussed in disclosures as the CARES Act changed 
		* how quickly companies could claim AMT refunds.
		drop if total_oldamt_10k == 1 & total_uncertain_10k == 0 & total_yes_10k == 0 & total_no_10k == 0  & total_boilerplate_10k == 0 
		
		duplicates drop cik, force 
		keep cik total_*
		save detail_10k, replace 
		
		* 10-Q database:
	* This data is from the WRDS SEC Clean Text and processing by hand:
	capture import delim "DIRECTORY\secdata_10Q_DETAIL.csv", delimiter(comma) bindquote(strict) varnames(1) maxquotedrows(unlimited) clear
	keep if camt_uncertain == 0 & camt_no == 0 & camt_yes == 0 & camt_boilerplate == 0 & camt_drop == 0 & camt_oldamt == 0 
	replace check = subinstr(check, ",", "",.) 
	outsheet using sec_10Q_RAW.csv , comma replace 
	
	* Because the text is based on mentions of CAMT/CAMT-related words, we need
	* to sum the type of disclosure by the firm. 
	
	foreach i in uncertain yes no drop oldamt boilerplate immaterial {
		egen total_`i'_10q = sum(camt_`i'),by(cik)
		replace total_`i'_10q = 1 if total_`i'_10q > 0 
		drop camt_`i'
		}
		*browse check if total_uncertain_10q == 0 & total_yes_10q == 0 & total_no_10q == 0 & total_drop_10q == 0 & total_cares_10q == 0 & total_boilerplate_10q == 0 
		
		duplicates drop cik, force 
		keep cik total_*
		drop if total_drop_10q == 1 & total_uncertain_10q == 0 & total_yes_10q == 0 & total_no_10q == 0  & total_oldamt_10q == 0 & total_boilerplate_10q == 0 
		drop if total_oldamt_10q == 1 & total_uncertain_10q == 0 & total_yes_10q == 0 & total_no_10q == 0  & total_boilerplate_10q == 0 
	
	save detail_10q, replace 

	* 8-K database:
	capture import delim "DIRECTORY\secdata_8K_DETAIL.csv", delimiter(comma) bindquote(strict) varnames(1) maxquotedrows(unlimited) clear
	* Because the text is based on mentions of CAMT/CAMT-related words, we need
	* to sum the type of disclosure by the firm. 	
	foreach i in uncertain yes no drop oldamt boilerplate immaterial {
		egen total_`i'_8k = sum(camt_`i'),by(cik)
		replace total_`i'_8k = 1 if total_`i'_8k > 0 
		drop camt_`i'
		}
		drop if total_drop_8k == 1 & total_uncertain_8k == 0 & total_yes_8k == 0 & total_no_8k == 0  & total_oldamt_8k == 0 & total_boilerplate_8k == 0 
		drop if total_oldamt_8k == 1 & total_uncertain_8k == 0 & total_yes_8k == 0 & total_no_8k == 0  & total_boilerplate_8k == 0 
			
		duplicates drop cik, force 
		keep cik total_*
		save detail_8k, replace 
		
use compustat_data, clear 
	keep gvkey cik 
	gen X = 1 
	merge m:1 cik using detail_10k
	keep if _merge == 1 
	duplicates drop gvkey, force
	egen count = sum(X)
	gen note = "2. Compustat firms matched to 10-K discussing CAMT"
	duplicates drop note, force 
	append using count_data 
	capture drop _merge 
	save count_data, replace 
	
use compustat_data, clear 
	gen X1 = 1 if camt_liab_2021_3 > 0 
	gen X2 = 1 if camt_liab_2022_3 > 0 
		replace X1 = 0 if missing(X1)
		replace X2 = 0 if missing(X2)
	duplicates drop gvkey, force 
	keep gvkey cik X1 X2 camt_liab_2021_3 camt_liab_2022_3
	drop if missing(cik)
	merge 1:1 cik using detail_10k 
	keep if _merge == 3 
	gen X = 1 
	egen count = sum(X)
	egen count_2021 = sum(X1)
	egen count_2022 = sum(X2)
	egen total_2021 = sum(camt_liab_2021_3)
	egen total_2022 = sum(camt_liab_2022_3)
	gen note = "2. Compustat firms matched to 10-K discussing CAMT"
	duplicates drop note, force 
	keep count note count_2021 count_2022 total_2021 total_2022 
	merge 1:1 note using count_data 
	drop _merge
	save count_data, replace 
	
use compustat_data, clear 
	keep gvkey cik 
	gen X = 1 
	merge m:1 cik using detail_10q
	keep if _merge == 1 
	duplicates drop gvkey, force
	egen count = sum(X)
	gen note = "3. Compustat firms matched to 10-Q discussing CAMT"
	duplicates drop note, force 
	append using count_data 
	capture drop _merge 
	save count_data, replace 
	
use compustat_data, clear 
	gen X1 = 1 if camt_liab_2021_3 > 0 
	gen X2 = 1 if camt_liab_2022_3 > 0 
		replace X1 = 0 if missing(X1)
		replace X2 = 0 if missing(X2)
	duplicates drop gvkey, force 
	keep gvkey cik X1 X2 camt_liab_2021_3 camt_liab_2022_3
	drop if missing(cik)
	merge 1:1 cik using detail_10q
	keep if _merge == 3 
	gen X = 1 
	egen count = sum(X)
	egen count_2021 = sum(X1)
	egen count_2022 = sum(X2)
	egen total_2021 = sum(camt_liab_2021_3)
	egen total_2022 = sum(camt_liab_2022_3)
	gen note = "3. Compustat firms matched to 10-Q discussing CAMT"
	duplicates drop note, force 
	keep count note count_2021 count_2022 total_2021 total_2022 
	merge 1:1 note using count_data 
	drop _merge
	save count_data, replace 
	
use compustat_data, clear 
	keep gvkey cik 
	gen X = 1 
	merge m:1 cik using detail_8k
	keep if _merge == 1 
	duplicates drop gvkey, force
	egen count = sum(X)
	gen note = "4. Compustat firms matched to 8-K discussing CAMT"
	duplicates drop note, force 
	append using count_data 
	capture drop _merge 
	save count_data, replace 
	
use compustat_data, clear 
	gen X1 = 1 if camt_liab_2021_3 > 0 
	gen X2 = 1 if camt_liab_2022_3 > 0 
		replace X1 = 0 if missing(X1)
		replace X2 = 0 if missing(X2)
	duplicates drop gvkey, force 
	keep gvkey cik X1 X2 camt_liab_2021_3 camt_liab_2022_3
	drop if missing(cik)
	merge 1:1 cik using detail_8k
	keep if _merge == 3 
	gen X = 1 
	egen count = sum(X)
	egen count_2021 = sum(X1)
	egen count_2022 = sum(X2)
	egen total_2021 = sum(camt_liab_2021_3)
	egen total_2022 = sum(camt_liab_2022_3)
	gen note = "4. Compustat firms matched to 8-K discussing CAMT"
	duplicates drop note, force 
	keep count note count_2021 count_2022 total_2021 total_2022 
	merge 1:1 note using count_data 
	drop _merge
	save count_data, replace 
	
	use detail_8k, clear 
	merge 1:1 cik using detail_10q 
	drop _merge 
	merge 1:1 cik using detail_10k 
	drop _merge 
	foreach i in uncertain yes no drop oldamt boilerplate immaterial {
		replace total_`i'_8k = 0 if missing(total_`i'_8k)
		replace total_`i'_10k = 0 if missing(total_`i'_10k)
		replace total_`i'_10q = 0 if missing(total_`i'_10q)
		}
	drop if missing(cik)
	destring cik, replace

	merge 1:m cik using compustat_data
	rename _merge mergex 
	save temp, replace 
	
	keep if _merge == 3 | mergex == 3
	duplicates drop gvkey, force
	egen count = sum(X)
	gen note = "5. Compustat firms matched to any disclosure discussing CAMT"
	duplicates drop note, force 
	append using count_data 
	capture drop _merge 
	save count_data, replace 
	
use temp, clear 
	gen X1 = 1 if camt_liab_2021_3 > 0 
	gen X2 = 1 if camt_liab_2022_3 > 0 
		replace X1 = 0 if missing(X1)
		replace X2 = 0 if missing(X2)
	duplicates drop gvkey, force 
	keep gvkey cik X1 X2 camt_liab_2021_3 camt_liab_2022_3 _merge mergex 
	drop if missing(cik)
	keep if _merge == 3 | mergex == 3
	gen X = 1 
	egen count = sum(X)
	egen count_2021 = sum(X1)
	egen count_2022 = sum(X2)
	egen total_2021 = sum(camt_liab_2021_3)
	egen total_2022 = sum(camt_liab_2022_3)
	gen note = "5. Compustat firms matched to any disclosure discussing CAMT"
	duplicates drop note, force 
	keep count note count_2021 count_2022 total_2021 total_2022 
	merge 1:1 note using count_data 
	drop _merge
	save count_data, replace 	
	sort note

* Build full disclosure data file:	
use detail_8k, clear 
	merge 1:1 cik using detail_10q 
	drop _merge 
	merge 1:1 cik using detail_10k 
	drop _merge 
	foreach i in uncertain yes no drop cares boilerplate {
		replace total_`i'_8k = 0 if missing(total_`i'_8k)
		replace total_`i'_10k = 0 if missing(total_`i'_10k)
		replace total_`i'_10q = 0 if missing(total_`i'_10q)
		}
	drop if missing(cik)
	save sec_detail, replace 
	
* We now match Compustat data to CAMT disclosures 	
use compustat_data, clear 	
drop if missing(cik)
destring cik, replace
capture drop _merge
merge m:1 cik using sec_detail
	
drop if _merge == 2	

*browse conm camt_liab_2021_3 camt_liab_2022_3  
gen boilerplate = total_boilerplate_8k + total_boilerplate_10q + total_boilerplate_10k 
gen uncertain = total_uncertain_8k + total_uncertain_10q + total_uncertain_10k 
gen yes = total_yes_8k + total_yes_10q + total_yes_10k 
gen no = 	total_no_8k + total_no_10q + total_no_10k 
gen dropx = total_drop_8k + total_drop_10q + total_drop_10k 
gen oldamt = total_oldamt_8k + total_oldamt_10q + total_oldamt_10k 
gen immaterial = total_immaterial_10k + total_immaterial_10q + total_immaterial_8k

keep if _merge == 3
	
gen only_boiler = 1 if boilerplate > 0 & uncertain == 0 & yes == 0 & no == 0 & immaterial == 0 
gen only_uncert = 1 if uncertain > 0 & yes == 0 & no == 0 & immaterial == 0 
gen only_yes = 1 if yes > 0 & no == 0 & immaterial == 0
gen only_no = 1 if no > 0 & yes == 0 & immaterial == 0 
gen only_immat = 1 if immaterial > 0 
gen switch = 1 if yes > 0 & no > 0 	
gen exp_uncert = 1 if uncertain > 0 
	* Keep only companies that have expected CAMT in 2022:
	keep if camt_liab_2022_3 > 0 
	duplicates drop gvkey, force 
	
	gsort -camt_liab_2022_3 
	*Create table 6: browse conm camt_liab_2022_3 boilerplate uncertain yes no immaterial 

* Create Table 5:
	* Grab the DTA/DTLs:
	* This data file was created earlier in the program (see prior to first step)
	use rec, clear 
	rename cik cik_code 
	tostring(cik_code),replace
	rename tic ticker
	merge 1:m ticker using "C:\Users\nborn\Dropbox (Penn)\Project-CAMT\Data\calcbench_normalizedbreakout.dta"
	drop if _merge == 2 
	gen month = month(end_date)
	gen day = day(end_date)
	gen double acct_end_datadate = fiscal_year * 10000 + month * 100 + day 
	gen tax_year = 2022 if acct_end_datadate >= 20220701 & acct_end_datadate <= 20230630 
	replace tax_year = 2021 if acct_end_datadate >= 20210701 & acct_end_datadate <= 20220630 
	replace tax_year = 2020 if acct_end_datadate >= 20200701 & acct_end_datadate <= 20210630 
	
	drop if missing(tax_year)
	
	* Remove line items related to AFSI: foreign earnings, SALT, pensions, and totals
	* Drop if the DTL is related to foreign earnings
		drop if strpos(label, "foreign earning") > 0
		drop if strpos(label, "Foreign earning") > 0
		drop if strpos(label, "foreign tax") > 0
		drop if strpos(label, "Unremitted") > 0 
		drop if strpos(label, "earnings of foreign") > 0 
		drop if strpos(label, "Earnings of foreign") > 0 
		drop if strpos(label, "non-U.S.") > 0 
		drop if strpos(label, "GILTI") > 0 
		drop if strpos(label, "Foreign tax") > 0
		drop if strpos(label, "Foreign Earnings") > 0 
		
	* Drop if DTL is related to SALT
		drop if strpos(label, "state income") > 0 
		drop if strpos(label, "State taxes") > 0 
		drop if strpos(label, "State deferred") > 0 
		drop if strpos(label, "State Taxes") > 0
		
	* Drop if DTL is related to pensions:
		drop if strpos(label, "pension") > 0 
		drop if strpos(label, "Pension") > 0 
		drop if strpos(label, "Benefit Plans") > 0 
		drop if strpos(label, "Employee benefit") > 0 
		drop if strpos(label, "defined benefit") > 0 
		drop if strpos(label, "employee benefit") > 0 
		drop if strpos(label, "Retirement") > 0 
	* Drop aggregate numbers:
		drop if strpos(label, "Total gross") > 0 
		drop if strpos(label, "Subtotal") > 0 
		drop if strpos(label, "Total") > 0 
		drop if strpos(label, "Tax on un") > 0	
		drop if label == "Net deferred tax liability"	
		drop if label == "Deferred tax liabilities"		
		drop if label == "Deferred tax assets"		
		drop if label == "Net deferred tax liabilities"		
		drop if label == "Deferred tax liabilities, net"		
		drop if label == "Deferred tax liabilities, gross"		
		drop if label == "Net DTL"		
		drop if label == "Gross deferred tax liabilities"		
		drop if label == "Deferred income tax, liabilities"		
		drop if label == "Net Deferred Tax (Liabilities) Assets"		
		drop if label == "Non-Current Deferred tax liability"		
		drop if label == "Net deferred tax (liability)"		
		drop if label == "Deferred Tax Liabilities, Net"		
		drop if label == "Deferred Tax Liabilities"		
		drop if label == "Deferred income tax liabilities"		
		drop if label == "Deferred income taxes, liabilities, gross"		
		drop if label == "Deferred tax liabilities (included in other noncurrent liabilities)"		
		drop if label == "Net deferred tax assets (liabilities)"		

		* Drop spectrum (as CAMT adjusts for this):
		drop if strpos(label, "Spectrum") > 0 
				
* Get timeseries so that a delta can be calculated:
	* remove duplicate firm-year-labels:
		egen updated_value = sum(effective_value),by(ticker tax_year label)
		duplicates drop ticker tax_year label updated_value, force 
		drop effective_value 
		gen double effective_value = updated_value 
		egen label_cd = group(label)
		duplicates tag ticker tax_year label_cd, gen(X)
		egen max_date = max(acct_end_datadate),by(ticker tax_year)
		drop if X > 0 & max_date > acct_end_datadate
		drop X 
		duplicates drop ticker tax_year label_cd effective_value , force
		duplicates tag ticker tax_year label_cd, gen(X)
		drop if X > 0 & effective_value == 0 

	* Set up timeseries for this:
	egen label_group = group(ticker label_cd)
	xtset label_group tax_year
	sort label_group tax_year
	* Calculate change in DTL:
	gen DTL = effective_value 
	gen DTL_inc = DTL - L.DTL
	gen DTL_inc_only = DTL_inc if DTL_inc > 0 
		replace DTL_inc_only = 0 if missing(DTL_inc_only)
	* Keep only 2022:
	keep if tax_year == 2022 
	
	* Reclassify some labels:
	gen og_label = label 
		* Goodwill and intangibles:
			replace label = "Goodwill and intangibles" if strpos(label, "Goodwill")
			replace label = "Goodwill and intangibles" if strpos(label, "intangible")
			replace label = "Goodwill and intangibles" if strpos(label, "goodwill")
			replace label = "Goodwill and intangibles" if strpos(label, "Intangible")
			replace label = "Goodwill and intangibles" if strpos(label, "Trade")
		* Leases, right of use assets, etc.:
			replace label = "Leases, right of use assets, etc." if strpos(label, "Leas")
			replace label = "Leases, right of use assets, etc." if strpos(label, "lease")
			replace label = "Leases, right of use assets, etc." if strpos(label, "Right-of-use")
			replace label = "Leases, right of use assets, etc." if strpos(label, "ROU")
			replace label = "Leases, right of use assets, etc." if strpos(label, "Right of use")
			replace label = "Leases, right of use assets, etc." if strpos(label, "Right of Use")
			replace label = "Leases, right of use assets, etc." if strpos(label, "Right-to-use")	
		* Unrealized gains and losses:
			replace label = "Unrealized gains and losses" if strpos(label, "unrealized gain")
			replace label = "Unrealized gains and losses" if strpos(label, "Unrealized gain")
			replace label = "Unrealized gains and losses" if strpos(label, "Unrealized")
		* OCI
			replace label = "Other comprehensive income" if strpos(label, "OCI")
			replace label = "Other comprehensive income" if strpos(label, "Other comprehensive")
		* Inventory
			replace label = "Inventory-related" if strpos(label, "Inventory")
			replace label = "Inventory-related" if strpos(label, "inventory")
			replace label = "Inventory-related" if strpos(label, "inventor")
		* Acqusition related:
			replace label = "Acquisition-related" if strpos(label, "Acquisition")
			replace label = "Acquisition-related" if strpos(label, "acquired")
			replace label = "Acquisition-related" if strpos(label, "acquisition")
		* Mortgatge servicing rights:
			replace label = "Mortgage servicing rights" if strpos(label, "Mortgage servic")
			replace label = "Mortgage servicing rights" if strpos(label, "MSR")
		* Depreciation-related:
			replace label = "Depreciation-related" if strpos(label, "depreciation")
			replace label = "Depreciation-related" if strpos(label, "Depreciation")
			replace label = "Depreciation-related" if strpos(label, "Property")
			replace label = "Depreciation-related" if strpos(label, "Plant")
			replace label = "Depreciation-related" if strpos(label, "Fixed")
			replace label = "Depreciation-related" if strpos(label, "Long-lived")
		
		* Security valuation:
			replace label = "Securities valuation adjustments" if strpos(label, "Securiti")
			replace label = "Securities valuation adjustments" if strpos(label, "Security")
			replace label = "Securities valuation adjustments" if strpos(label, "Mark")
			replace label = "Securities valuation adjustments" if strpos(label, "securities")
		* Deferred income:
			replace label = "Deferred income" if strpos(label, "Deferred Income")
			replace label = "Deferred income" if strpos(label, "Deferral of Incom")
			replace label = "Deferred income" if strpos(label, "commissions")
			replace label = "Deferred income" if strpos(label, "Deferred profit")
			replace label = "Deferred income" if strpos(label, "Deferred rev")
			replace label = "Deferred income" if strpos(label, "Deferral of profit on home")
		* Partnership related 
			replace label = "Partnership-related" if strpos(label, "Partnership")
			replace label = "Partnership-related" if strpos(label, "partnership")
		* Tax credit carryforwards
			replace label = "Tax credit carryforwards" if strpos(label, "Tax credit carryforward")
		* Debt:
			replace label = "Debt" if strpos(label, "Loans")
			replace label = "Debt" if strpos(label, "Long-term contract")
			replace label = "Debt" if strpos(label, "debt")
			replace label = "Debt" if strpos(label, "Debt")
			replace label = "Debt" if strpos(label, "Original issue")
		
		* Other:
			replace label = "Other" if label== "Other"
			replace label = "Securities valuation adjustments" if strpos(label, "Security")
			replace label = "Securities valuation adjustments" if strpos(label, "Security")
			replace label = "Securities valuation adjustments" if strpos(label, "Security")
			replace label = "Securities valuation adjustments" if strpos(label, "Security")
			
	egen largest_DTL = max(DTL_inc),by(ticker)
	egen largest_DTL_only = max(DTL_inc_only),by(ticker)
	egen agg_DTL = sum(DTL_inc),by(label)
	egen agg_DTL_only = sum(DTL_inc_only),by(label)
	gen Z = 0
		replace Z = 1 if DTL_inc > 0 
	duplicates drop ticker label, force 
	egen N_DTL_only = sum(Z),by(label)
	format agg_DTL %12.0fc
	format agg_DTL_only %12.0fc
	gsort -agg_DTL_only label
	browse label agg_DTL_only N_DTL_only agg_DTL 
	
	keep if DTL_inc == largest_DTL 
	sort ticker
	* Create Table 5, panel A: browse ticker label DTL_inc
	drop if missing(DTL_inc)
* Get changes in DTAs:
use rec, clear 
	rename cik cik_code 
	tostring(cik_code),replace
	rename tic ticker
	merge 1:m ticker using "C:\Users\nborn\Dropbox (Penn)\Project-CAMT\Data\calcbench_normalfootnotes.dta"
	gen label = metric 
	gen effective_value = value
	drop if _merge == 2 
	gen month = month(end_date)
	gen day = day(end_date)
	gen double acct_end_datadate = fiscal_year * 10000 + month * 100 + day 
	gen tax_year = 2022 if acct_end_datadate >= 20220701 & acct_end_datadate <= 20230630 
	replace tax_year = 2021 if acct_end_datadate >= 20210701 & acct_end_datadate <= 20220630 
	replace tax_year = 2020 if acct_end_datadate >= 20200701 & acct_end_datadate <= 20210630 
	drop if missing(tax_year)
	keep if strpos(metric, "DeferredTaxAsset")
	
	* Drop if the DTL is related to foreign earnings
		drop if strpos(label, "foreign earning") > 0
		drop if strpos(label, "foreign tax") > 0
		drop if strpos(label, "Unremitted") > 0 
		drop if strpos(label, "earnings of foreign") > 0 
		drop if strpos(label, "Earnings of foreign") > 0 
		drop if strpos(label, "non-U.S.") > 0 
	* Drop if DTL is related to SALT
		drop if strpos(label, "state income") > 0 
		drop if strpos(label, "State taxes") > 0 
		drop if strpos(label, "State deferred") > 0 
		
	* Drop if DTL is related to pensions:
		drop if strpos(label, "pension") > 0 
		drop if strpos(label, "Pension") > 0 	
	* Drop if rate rec is still there
		drop if strpos(label, "EffectiveIncomeTaxRateRecon") > 0 	
		drop if strpos(label, "IncomeTaxReconcil") > 0 
		
	* Drop if it's providng the total:
		drop if metric == "DeferredTaxAssetsLiabilitiesNet"
		drop if metric == "DeferredTaxAssetsNet"
		drop if metric == "DeferredTaxAssetsStateTaxes"
		drop if metric == "DeferredTaxAssetsLiabilitiesNet"
		drop if metric == "DeferredTaxAssetsLiabilitiesNet"
	
* Get timeseries so that a delta can be calculated:
	* remove duplicate firm-year-labels:
		egen label_cd = group(label)
		duplicates tag ticker tax_year label_cd, gen(X)
		egen max_date = max(acct_end_datadate),by(ticker tax_year)
		drop if X > 0 & max_date > acct_end_datadate
		drop X 
		duplicates drop ticker tax_year label_cd effective_value , force
		duplicates tag ticker tax_year label_cd, gen(X)
		drop if X > 0 & effective_value == 0 

	* Set up timeseries for this:
	egen label_group = group(ticker label_cd)
	xtset label_group tax_year
	sort label_group tax_year
	* Calculate change in DTA:
	gen DTA = effective_value 
	gen DTA_inc = DTA - L.DTA
	gen DTA_inc_only = DTA_inc if DTA_inc < 0 
	replace DTA_inc_only = 0 if missing(DTA_inc_only)
	* Keep only most recent tax year:
		egen max_year = max(tax_year),by(ticker)
		drop if tax_year < max_year 
	egen largest_DTA = min(DTA_inc),by(ticker)
	egen agg_DTA = sum(DTA_inc),by(label)
	egen agg_DTA_only = sum(DTA_inc_only),by(label)
	format agg_DTA %12.0fc
	gen Z = 0
		replace Z = 1 if DTA_inc < 0 
	duplicates drop ticker label, force 
	egen N_DTA_only = sum(Z),by(label)
	gsort agg_DTA_only
	browse metric agg_DTA_only N_DTA_only agg_DTA 
	keep if DTA_inc == largest_DTA 
	sort ticker
	drop if missing(DTA_inc)
	* Create table 5, panel B: browse ticker label DTA_inc 
	
* Grab the Rate rec:
use rec, clear 
	rename cik cik_code 
	tostring(cik_code),replace
	rename tic ticker
	merge 1:m ticker using "C:\Users\nborn\Dropbox (Penn)\Project-CAMT\Data\calcbench_normalfootnotes.dta"
	drop if _merge == 2 
	gen month = month(end_date)
	gen day = day(end_date)
	gen double acct_end_datadate = fiscal_year * 10000 + month * 100 + day 
	gen tax_year = 2022 if acct_end_datadate >= 20220701 & acct_end_datadate <= 20230630 
	replace tax_year = 2021 if acct_end_datadate >= 20210701 & acct_end_datadate <= 20220630 
	replace tax_year = 2020 if acct_end_datadate >= 20200701 & acct_end_datadate <= 20210630 
		drop if strpos(metric, "Foreign") > 0 
	
	drop if missing(tax_year)	
	gen keep = 0
	replace keep = 1 if strpos(metric, "IncomeTaxReconciliation")
	replace keep = 1 if strpos(metric, "EffectiveIncomeTaxRate")
	drop if metric == "EffectiveIncomeTaxRateContinuingOperations"
	keep if keep == 1 
	keep if tax_year == 2022
	gen tax_val = value if format_type == "currency"
	replace tax_val = pi * value if format_type == "percent"
	gen tax_val1 = tax_val if tax_val < 0 
	replace tax_val1 = 0 if missing(tax_val1)
	egen agg_recon = sum(tax_val),by(metric)
	egen agg_recon_ONLY = sum(tax_val1),by(metric)
	egen big_change = min(tax_val),by(ticker)
	gsort agg_recon_ONLY
	gen X = 1 if tax_val < 0 
		replace X = 0 if missing(X)
	egen N_metric_ONLY = sum(X),by(metric)
	duplicates drop metric, force 
	order metric agg_recon_ONLY N_metric_ONLY agg_recon
	browse metric agg_recon_ONLY N_metric_ONLY agg_recon 
	drop if tax_val != big_change 
	sort ticker
	* Create table 5, panel C: browse ticker metric tax_val 
	